Vue--- 子 --> 父 组件传递参数

来源:互联网 发布:js设置边框颜色 编辑:程序博客网 时间:2024/06/08 01:34
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <script src="js/vue.js"></script></head><body><div id="app">        <div>{{name}}</div>    <hr/>        <my-comp v-on:even="jieshou"></my-comp></div></body><script>        Vue.component("myComp",{            template:"<div>我是组件 <button @click='send'>点击我</button></div>",            data:function () {                return {                    zujian:{id:1,xingming:"小明"}                }            },            methods:{                send:function () {                    this.$emit("even",this.zujian)//$emit这个方法会触发一个事件                }            }        });    var app=new Vue({        el:"#app",        data:{            name:"原始数据"        },        methods:{            jieshou:function (msg) {                this.name=msg;                console.log("父组件被触发了");            }        }    })</script></html>
阅读全文
0 0
原创粉丝点击