<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://unpkg.com/vue@next"></script>
<style>
.red {
color: red;
}
</style>
</head>
<body>
<div id="root"></div>
<script>
const app = Vue.createApp({
template: `<div>
<form action="htttp://www.baidu.com" @click.prevent="handleClick(2, $event), handleclick2()">
<span v-bind:[attr]="msg">{{msg}}</span>
<button>提交</button>
</form>
<div>时间1:{{time}}</div>
<div>时间2:{{getDate()}}</div>
<div @click.self="handleclick2" style="width:100px;height:100px;background:pink">
<div @click.stop="testClick">阻止冒泡</div>
<div @click="testClick">阻止冒泡</div>
</div>
<demo class="red" name='1'/>
<p>{{count}}</p>
<input v-model="checkvalue" type="checkbox" false-value="hello" true-value="world"/> {{checkvalue}}
</div>`,
data(){
return {
msg: 'hello world',
attr: 'title',
count: 0,
checkvalue: 'hello'
}
},
computed: {
time() {
return Date.now()
}
},
methods: {
handleClick(num, event) {
this.count += num;
console.log(event);
},
handleclick2() {
console.log('handleclick2');
},
testClick(){
alert('只触发了一次');
},
getDate() {
return Date.now();
}
},
})
app.component('demo', {
template: `<div :class="$attrs.class">
样式绑定 $attrs:{{$attrs}}
</div>`
})
app.mount('#root')
</script>
</body>
</html>