vue在v 您所在的位置:网站首页 vue拼接字符串中点击事件 vue在v

vue在v

2023-06-18 04:13| 来源: 网络整理| 查看: 265

最近做项目,使用得vue作为基础框架。有这样一个需求,需要给返回来的富文本绑定事件,搜了一下众说纷纭。自己摸索了和总结出一套比较好用得方式。

 

利用JavaScript事件捕获,通过给使用v-html的标记绑定click事件,捕获到点击的标记。从而实现vue动态绑定dom元素事件的效果;

 

代码如下:

 

富文本数据:

"richTextContent": "Some Wi‑Fi networks are open and you can simply connect for internet access. Other Wi‑Fi networks are secure and require you to enter a password. Contact the Wi-Fi network's owner for the password.To search for and connect with available Wi-Fi networks:Swipe down from the top of your screen to open quick settings and then:Android 9: Touch ; hold .Android 8: Touch Wi Fi ; More settingsAndroid 7: Touch Wi Fi.Turn Wi-Fi on .Touch the Wi-Fi network you want to connect to.If the network is a secure one, enter the password.Make sure you enter the password correctly. Touch Show password to see what you’re typing.When your phone is connected, appears in the status bar. If the connection is poor, appears in the status bar.",

 

vue模板写法

 

script方法

test (event) { console.log(event.target.className) // testssss console.log(event.target.nodeName) // p if (event.target.nodeName === 'p' && event.target.className === 'testssss') { // 获取触发事件对象的属性 alert('a') } }

 

最终效果

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有