终于把vue官方的bug找到了,有两个bug,一个是main.js里定义的变量名称与html里div块里的id不符,一个是缺少挂载

正确的代码
html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Vue Mastery</title>
    <!-- Import Styles -->
    <link rel="stylesheet" href="./assets/styles.css" />
    <!-- Import Vue.js -->
    <script src="https://unpkg.com/vue@3.0.0-beta.12/dist/vue.global.js"></script>
  </head>
  <body>
    <div id="counter">
      Counter: {{ counter }}
    </div>
    

    <!-- Import Js -->
    <script src = "./main.js"></script>


    
  </body>
</html>

main.js

const Counter= {
  data() {
    return {
      counter: 0
    }
  },
  mounted() {
    setInterval(() => {
      this.counter++
    }, 1000)
  }
}
Vue.createApp(Counter).mount('#counter')

官方写的是
main.js

const CounterApp = {
  data() {
    return {
      counter: 0
    }
  },
  mounted() {
    setInterval(() => {
      this.counter++
    }, 1000)
  }
}

html

<div id="counter">
      Counter: {{ counter }}
    </div>

两个bug
CouterAPP vs Couter
漏了Vue.createApp(Counter).mount(’#counter’)
挂载的

上一篇:AMD规范和CommonJS规范


下一篇:简单记录vue下单元测试及Mock数据