這篇文章主要介紹VUE中v-html不能觸發(fā)點(diǎn)擊事件怎么辦,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

背景:后端返前端html格式的數(shù)據(jù),前端用v-html解析渲染,如:<a @click="show(1)"></a>,a標(biāo)簽?zāi)艹晒︿秩荆浣壎ǖ氖录o(wú)法觸發(fā)。
原因:vue沒(méi)有將其作為vue的模板解析渲染
解決方案:不用v-html而是component模板編譯
上干貨:
<template>
<div class="hello">
<h2>
我是父組件
</h2>
<div class="parent" id="parent">
</div>
</div>
</template>
<script>
import Vue from 'vue';
var MyComponent = Vue.extend({
template: '<a @click="show(1)">我是大魔王</a>',
methods: {
show(i) {
console.log(i);
},
}
});
var component = new MyComponent().$mount();
export default {
data() {
return {
}
},
methods: {
},
mounted() {
document.getElementById('parent').appendChild(component.$el);
}
}
</script>
<style scoped>
</style>頁(yè)面:

控制臺(tái):

以上是“VUE中v-html不能觸發(fā)點(diǎn)擊事件怎么辦”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前題目:VUE中v-html不能觸發(fā)點(diǎn)擊事件怎么辦-創(chuàng)新互聯(lián)
網(wǎng)站鏈接:http://chinadenli.net/article44/sheee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、響應(yīng)式網(wǎng)站、動(dòng)態(tài)網(wǎng)站、用戶體驗(yàn)、標(biāo)簽優(yōu)化、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容