- 前端绑定vue
- 前端绑定组件
- 通过组件调用vue中的事件
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<toto>
<toto-title slot="toto-title" :title="title"></toto-title>
<toto-items slot="toto-items" v-for="(item,index) in totoItems"
:item="item" :index="index" v-on:remove="removeItems(index)"></toto-items>
</toto>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>
<script>
Vue.component("toto",{
template:
'<div>\
<slot name="toto-title"></slot>\
<ul>\
<slot name="toto-items"></slot>\
</ul>\
</div>'
});
Vue.component("toto-title",{
props: ['title'],
template: '<div>{{title}}</div>'
});
Vue.component("toto-items",{
props: ['item','index'],
template: '<li>{{index}}-----{{item}} <button @click="remove">删除</button> </li>',
methods: {
remove: function (index) {
this.$emit('remove','index');
}
}
});
var vm = new Vue({
el: "#app",
data :{
title: "列表",
totoItems: ['狂神说JAVA','狂神说前端','狂神说Linux']
},
methods: {
removeItems: function (index) {
this.totoItems.splice(index,1);
}
}
});
</script>
</body>
</html>