想用vue写一个本地web应用(本地运行,所以不用CLI),刚刚学,遇到了一些问题,请指教。
HTML是这样的:
[HTML] 纯文本查看 复制代码 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./assets/js/vue.global.js"></script>
<link href="./assets/css/tailwind.min.css" rel="stylesheet">
</head>
<body>
<div id="app">
<div class="w-screen h-screen">
<button @click="mytext='新测试'">{{mytext}}</button>
<button @click="dosomething">{{mytext}}</button>
</div>
</div>
<script src="./assets/js/index.js"></script>
</body>
</html>
JS是这样的:
[JavaScript] 纯文本查看 复制代码 const Counter = {
data() {
return {
mytext: '测试'
}
},
mounted() {
// dosomething() {
// console.log('9999')
// }
// 官方demo是这样写的,但这样写vscode会报错
dosomething: () => {
console.log('执行了')
}
}
}
Vue.createApp(Counter).mount('#app')
运行直接报错:[Vue warn]: Property "dosomething" was accessed during render but is not defined on instance. at <App>
请问,这种报错代码应该怎么改,感谢指教。
|