Web前端教程 Vue 组件间传值 组件间传值,父子组(2)
时间:2019-08-17 15:23:08 作者:无名 浏览量:23
子组件往父组件传值
1、现在子组件中进行监听注册@click='handleItemClick'
2、在子组件中的methods中注册 handleItemClick
3、this.$emit("delete"); 子组件被点击时,向外触发一个delete事件,
4、同时需要在父组件中进行对该事件进行监听@delete="handleItemClick"
5、在父组件的methods中注册handleItemClick方法
*/
methods:{
handleItemClick:function () {
this.$emit("delete",this.index);
}
}
}
/*
// Vue提供的创建全局组件
Vue.component("todo-item",{
props:['todo'],
template:"<li>{{todo}}</li>"
});
*/
var app = new Vue({
el:'#app',
components:{
TodoItem:TodoItem
},
data:{
// list:['Hello','World'],
list:['Hello','World!'],
inputValue:'v-model'
},
methods: {
handleBtnClick:function () {
this.list.push(this.inputValue);
},
handleItemClick:function (index) {
this.list.splice(index,1);
}
}
});
</script>
</body>
</html>
<上一页12
- 软件性质:国产软件
- 授权方式:免费版
- 软件语言:简体中文
- 软件大小:39531 KB
- 下载次数:636 次
- 更新时间:2019/8/17 15:08:15
- 运行平台:WinAll...
- 软件描述:Visual Studio Code是一个轻量但功能强大的源代码编辑器,可在桌面... [立即下载]
相关资讯
相关软件