简体   繁体   English

为什么 v-model 在 vue.extend 中使用时不起作用?

[英]Why v-model not working when used in vue.extend?

I have a page structure similiar to this:我有一个类似于此的页面结构:

<main id="app">
  <div id="mount-place"></div>
</main>
<script type="text/x-template" id="my-template">
  ...some code here...
  <input type="text" v-model="address">
  ...some other code here...
</script>
<script>
var ExtendedElement = Vue.Extend({
  template: '#my-template',
  data: function() {
    return {
      address: {{ some_address|safe }};  // gets values from django
    }
  },
  mounted: function() {
    console.log(this.address);  // Works just fine
  }
});
new ExtendedElement().$mount('#mount-place');
</script>
...some unimportant logic here...
<script>
const app = new Vue({
  delimiters: ['[[', ']]'],
  el: '#app'
});
</script>

And the problem is it renders just fine, but v-model not working ie input shows nothing.问题是它渲染得很好,但v-model不工作,即输入什么都不显示。 When accessing it via console it shows values inside vue object. No errors or warnings.通过控制台访问它时,它在 vue object 中显示值。没有错误或警告。

So the problem here is calling new Vue .所以这里的问题是调用new Vue Solution is just deleting app variable and move delimiters to Vue.Extend call.解决方案只是删除app变量并将定界符移至Vue.Extend调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM