正确的代码
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’)
挂载的