最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why v-model is not working? - Stack Overflow

programmeradmin7浏览0评论

This is my very first code in Vue.js. I am following a simple online tutorial. After installing the application using the vue-cli, I created a simple ponent Test.vue which contains a simple input control bound to the message property of my model:

Test.vue

<template>
  <div 
    <input 
        type="text" 
        v-model="message"/>
    <br/>
    <p>The value of the input is: {{ message }}</p>
  </div>
</template>

<script>
    export default {  
      data:{
        message: 'My name'
      }
    };
</script>

<style>
</style>

Then I load this ponent inside the <App />. But when I write a text inside the input box, the <p> element is not updated...

What am I doing wrong? This looks pretty straightforward. Thanks you for your suggestions and pointing me to the right direction.

This is my very first code in Vue.js. I am following a simple online tutorial. After installing the application using the vue-cli, I created a simple ponent Test.vue which contains a simple input control bound to the message property of my model:

Test.vue

<template>
  <div 
    <input 
        type="text" 
        v-model="message"/>
    <br/>
    <p>The value of the input is: {{ message }}</p>
  </div>
</template>

<script>
    export default {  
      data:{
        message: 'My name'
      }
    };
</script>

<style>
</style>

Then I load this ponent inside the <App />. But when I write a text inside the input box, the <p> element is not updated...

What am I doing wrong? This looks pretty straightforward. Thanks you for your suggestions and pointing me to the right direction.

Share Improve this question edited Dec 14, 2017 at 23:46 Rob 15.2k30 gold badges48 silver badges73 bronze badges asked Dec 14, 2017 at 23:32 TheSoulTheSoul 5,35614 gold badges48 silver badges82 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 13

In a ponent, data must be a function.

export default {  
  data(){
    return {
      message: 'My name'
    }
  }
};

Also, your template is missing a > in the first div, but I'm guessing that happened writing the question.

<template>
  <div>
    <input 
        type="text" 
        v-model="message"/>
    <br/>
    <p>The value of the input is: {{ message }}</p>
  </div>
</template>
发布评论

评论列表(0)

  1. 暂无评论