vue组件常用传值
一.使用Props传递数据 在父组件中使用儿子组件 <template> <div> 父组件:{{mny}} <Son1 :mny="mny"></Son1> </div> </template> <script> import Son1 from "./Son1"; export default { components: { Son1 }, data() { return { mny: 100 }; } }; </script> 子组件接受父组件的属性 二.使用$emit使用 子组件触发父组件方法,通过回调的方式将修改的内容传递给父组件 <template> <div> 父组件:{{mny}} <Son1 :mny="mny" @input="change"></Son1> </div> </template> <script> import Son1 from "./Son1"; export default { methods: { change(mny) { this.mny = mny; } }, components: { Son1 }, data() { return { mny: 100 }; } }; </script> 子组件触发绑定自己身上的方法 <template> <div> 子组件1: {{mny}} <button @click="$emit(