100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Vue父组件向子组件传值

Vue父组件向子组件传值

时间:2022-03-08 20:55:47

相关推荐

Vue父组件向子组件传值

<!DOCTYPE html><html><head><meta charset="utf-8"><title></title><script src="libs/vue.min.js"></script></head><body><div id="app"><!-- 绑定自定义属性来传递父组件的值 --><content-compo :msg="msg"></content-compo></div><template id="content"><div><h4>子组件接收到父组件 传递 的值:{{msg}}</h4></div></template><script>const contentEle = ponent('content', {name: 'Content',template: '#content',data:function(){return{message:'我是子组件中的data'}},//对绑定的自定义属性值进行接收props: ['msg'],created: function() {// 子组件创建完成之后,用自己的私有属性接收父组件传来的值this.message=this.msg;console.log('receive msg:', this.message)}})const app = new Vue({el: '#app',data: {msg: '我是父组件 data中的值'},components: {// 注册私有组件contentCompo: contentEle}})</script></body></html>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。