1.click事件
2.鼠标事件
mouseup
mousedown
mouseleave
3.dblclick
4. touch
5.实例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id='app'>
{{message}} {{message + message}}
<div :id="message"></div>
<todo-list></todo-list>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script>
Vue.component('todo-item', {
props: {
title: String,
del: {
type: Boolean,
default: false
}
},
template: '' +
'<li>\n' +
'<span v-if="del">{{title}}</span>\n' +
'<span v-else style="text-decoration: line-through">{{title}}</span>\n' +
'<button v-show="!del" @click.stop="handlerClick">删除</button>\n' +
'</li>',
data: function () {
return {}
},
methods: {
handlerClick: function (e) {
e.stop
console.log('点击删除按钮')
this.$emit('delete', this.title)
}
}
})
Vue.component("todo-list", {
template: '' +
'<ul>\n' +
'<todo-item @delete="handlerDelete" v-for="item in list" data-test="dd" :title="item.title" :del="item.del"></todo-item>\n' +
'</ul>',
data: function () {
return {
list: [
{
title: '课程1',
del: false
},
{
title: '课程2',
del: true
}
]
}
},
methods: {
handlerDelete(val) {
console.log('handlerDelete', val)
}
}
})
var vm = new Vue({
el: '#app',
data: {
message: 'hello world',
list: [
{
title: '课程1',
del: false
},
{
title: '课程2',
del: true
}
]
}
})
</script>
</body>
</html>