Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

vue directive失效的问题

这是html:

<div v-html="dialog_format_html(scope.row.html)" >

dialog_format_html函数的代码:

dialog_format_html: function (value) {
    if (!value) return ''
    if(this.dialog.type == 'url' || this.dialog.type == 'area'){
        return `<a v-link target="_blank" href="${value}">${value}</a>`
    }else{
        return value;
    }
},

v-link就是我定义的指令。如果一段a标签,正常情况下是可以触发指令的。所以指令是正常运行的。
现在的问题就是通过v-html构造的东西,v-link失效了。如何解决这个问题呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

v-html会把内容按普通HTML插入,不会作为Vue模板进行编译的,可以做成组件来代替


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...