VueJS TypeError: alert is not a function
VueJS TypeError: alert is not a function
我正在尝试学习 VueJS。我已经制作了我的第一个 vue,并且正在测试指令。这是我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Partie 1 Chapitre 3 - Vue Mart</title>
</head>
<body>
<div id="app">
<button v-on:click="alert('hello')">Cliquez ici !</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
costOfApples: 5,
costOfBananas: 2,
costOfCoconuts: 8,
favoriteColor: 'rose'
},
//Propriétés calculées
computed: {
totalAmount() {
return this.costOfApples + this.costOfBananas + this.costOfCoconuts
},
label() {
return ': '+ this.favoriteColor
}
}
})
</script>
</body>
</html>
当我点击我的按钮时出现这个错误:
TypeError: alert is not a function
[Vue warn]: Error in v-on handler: "TypeError: alert is not a function"
[Vue warn]: Property or method "alert" is not defined on the instance but referenced during
render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
(found in <Root>)
我真的不知道从哪里开始寻找。对我来说,我的代码似乎没问题。
感谢您的帮助
你应该在你的方法中定义警报
methods(){
alert(){
// do something
}
}
我正在尝试学习 VueJS。我已经制作了我的第一个 vue,并且正在测试指令。这是我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Partie 1 Chapitre 3 - Vue Mart</title>
</head>
<body>
<div id="app">
<button v-on:click="alert('hello')">Cliquez ici !</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
costOfApples: 5,
costOfBananas: 2,
costOfCoconuts: 8,
favoriteColor: 'rose'
},
//Propriétés calculées
computed: {
totalAmount() {
return this.costOfApples + this.costOfBananas + this.costOfCoconuts
},
label() {
return ': '+ this.favoriteColor
}
}
})
</script>
</body>
</html>
当我点击我的按钮时出现这个错误:
TypeError: alert is not a function
[Vue warn]: Error in v-on handler: "TypeError: alert is not a function"
[Vue warn]: Property or method "alert" is not defined on the instance but referenced during
render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
(found in <Root>)
我真的不知道从哪里开始寻找。对我来说,我的代码似乎没问题。 感谢您的帮助
你应该在你的方法中定义警报
methods(){
alert(){
// do something
}
}