javascriptを追加するまで、アプリケーションのすべてが正常に動作していました。今度は、コンソールでエラーが継続的に発生します。プロパティまたはメソッドが.vueファイルで定義されていない
Property or method "show" 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.
と同様に、このエラー:
は、私はこのエラーを取得する
TypeError: _vm.show is not a function at click App.vue?d98c:25 at HTMLButtonElement.invoker vue.esm.js?efeb:1906
望ましい結果: "loginBtn" をクリックしてアラートが "クリック" プロンプトが表示されます。
マイコード:
// app.vue script
export default {
name: 'app'
}
var show = new Vue({
el: '#loginBtn',
data: {
n: 0
},
methods: {
show: function(event) {
targetId = event.currentTarget.id;
alert('click')
}
}
})
<!-- the button -->
<template>
<div>
<button v-on:click="show($event)" id="loginBtn">Login</button>
</div>
</template>
Yayyy! Tysmは、何時間も探していましたが、これを実現する方法は非常に多くあります。また、私が見つけた他の人は、それが輸出の中でなければならないと説明したが、ほとんどが(「新しいVue」を作成すると言った) – hannacreed
助けてくれてうれしい!そして、 '.vue'ファイルは' vue-loader'がいくつかの定型コードを抽象化するために使用する特定のフォーマットに従います( 'new Vue'を使ってインスタンス化する必要があります)。私は私の記事を参考にして、参考になると思われるドキュメントにリンクしました。 – thanksd