Vuejs 2.0属性未在页面源中显示

时间:2017-09-01 00:27:29

标签: html5 templates vuejs2

在Vue 1.0.28中,我可以这样做:

Vue.component('singletext', {
      template: `<input type=text value="{{item.value}}" />`,
      props: {
          item: Object
      }
});

并在查看页面源时获取此信息:

<input type="text" value="a value">

但是在Vue 2.0中,我必须使用v-bind,它在屏幕上正确显示了值,但是页面源缺少这样的属性:

Vue.component('singletext', {
      template: `<input type=text :value="item.value" />`,
      props: {
          item: Object
      }
});

页面来源:

<input type="text">

无论如何都要确保正确生成页面源? (没有SSR)

1 个答案:

答案 0 :(得分:1)

好吧,渲染功能有效。

Vue.component("singletext", {
  props:{item: Object},
  render(h){
   return h('input', {attrs: {value: this.item.value, type: "text"}})
  }
})

我无法想到更好的方法。如果您需要更多类似功能的模板,可以add them

这是example