Vue.js 极简小例: 点击事件

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。

代码:

<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>

运行效果:

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值