template用双引号还是报错

来源:1-6 组件概念初探,对 TodoList 进行组件代码拆分

杨洋洋

2021-07-13

<script>
  Vue.createApp({
    data() {
      return {
        inputValue: '',
        list: []
      }
    },
    methods: {
      handleAddItem() {
        this.list.push(this.inputValue);
        this.inputValue = '';
      }
    },
    template: "
      <div>
        <input type='text' v-model='inputValue'>
        <button v-on:click='handleAddItem'>增加</button>
        <ul>
          <li v-for='(item, index) of list'>{{item}} {{index}}</li>
        </ul>
      </div>
    "
  }).mount('#root')
</script>
写回答

1回答

杨洋洋

提问者

2021-07-13

知道了,原来是要用`

```

template: `

      <div>

        <input type='text' v-model='inputValue'>

        <button v-on:click='handleAddItem'>增加</button>

        <ul>

          <li v-for='(item, index) of list'>{{item}} {{index}}</li>

        </ul>

      </div>

    `

```

0
0

Vue3入门与项目实战 掌握完整知识体系

明星讲师DELL亲授,全方位知识点+高匹配度项目,入门到深度掌握

3382 学习 · 1454 问题

查看课程