父组件向子组件传值的方法很简单,就一句话。vue父组件向子组件传值的方法:必须使用props属性来定义父组件传递过来的数据,然后把父组件里的数据传递到子组件中就行了。

vue子组件给父组件传值(vue父组件向子组件传值的方法)(1)

1.请看下面这个例子,你就懂了

<!Doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GBK"/> <title>vue父组件向子组件传值方法</title> </head> <body> <div id="app"> <son :finfo="msg"></son> </div> <script src="http://img.studyofnet.comhttps://cdn.jsdelivr.net/npm/vue"></script> <script> var vm = new Vue({ el: '#app', data: { msg: '我是父组件里的消息' }, components: { son: { template: '<h1>我是子组件 --- {{finfo}}</h1>', props: ['finfo'] } } }); </script> </body> </html>

2.结果如下:

vue子组件给父组件传值(vue父组件向子组件传值的方法)(2)

除注明外的文章,均为来源:老汤博客,转载请保留本文地址!

原文地址:http://tangjiusheng.com/vue/170.html

,