代码:
<template>
<div>
<!-- jy_mothed 是在 js 中自定义的方法 -->
<button v-on:click="jy_mothed">想念</button>
<br><br>
<!-- 点击事件 参数化调用 -->
<button v-on:click="loveU('愿我如星君如月... 夜夜流光相皎洁 ...')">此刻</button>
<button v-on:click="loveU('君当作磐石,妾当作蒲苇 , 蒲苇纫如丝,磐石无转移 ... ')">今生</button>
</div>
</template>
<script>
export default {
data () {
return {
name: '在我每一次敲击键盘时 ... 想念,在我的每一行代码之间 ... '
}
},
methods: {
jy_mothed: function (event) {
alert('想你,' + this.name) // this:当前 Vue 实例
if (event) { // 原生 DOM 事件
alert(event.target.tagName)
}
},
loveU: function (message) {
alert(message);
}
}
}
</script>运行效果:


