vue v html replace,vuejs 2 v-for :key not working, html being replace

I had a little play with this and it appears that Vue does not re-render the entire list when using or if you use a component but it does with v-html. Heres the fiddle for the comparison:

https://jsfiddle.net/cxataxcf/

The key actually isn't needed here because the list isn't being re-ordered, so your issue isn't to do with :key but rather with v-html. Heres what the docs say about v-html:

The contents are inserted as plain HTML - data bindings are ignored. Note that you cannot use v-html to compose template partials, because Vue is not a string-based templating engine. Instead, components are preferred as the fundamental unit for UI reuse and composition.

So I guess this is where the problem lies.

It might be worth raising an issue on Vue's github page to see whether this is the expected behavior for v-html, but Vue 2.0 is much more heavily focused on components than vue 1.x and doesn't appear to recommend using v-html, so it may just be that you need to re-factor your code to use components instead.

Edit

The solution to this problem is to simply wrap the code in a component and pass the HTML as a prop:

Vue.component('unknown-html', {

props: {

html: ""

},

template: '

})

The markup:

And the View model:

var app = new Vue({

el: '#app',

data: {

numInputs: 1,

stuff: [{

'html':''

}, {

'html':'Foo'

}]

}

})

Here's the JSFiddle: https://jsfiddle.net/wrox5acb/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值