タイトルのとおりなのですが、templateのクリックイベントに
testAlert関数
が渡せません。
出ているエラーはこちらです。
Property "testAlert" was accessed during render but is not defined on instance. at <MyTemplate> at <App>
templateを使う際にはなにか別途設定が必要なのでしょうか?
html
<body> <div id="app"> <my-template></my-template> </div> <script src="./vue.js"></script> </body>
JavaScript
const myApp = { data() { return {}; }, methods: { // 渡したい関数 testAlert() { alert("テストです"); }, }, }; const app = Vue.createApp(myApp); app.component("my-template", { template: ` <button @click="testAlert">ボタン</button> `, }); app.mount("#app");
ご存じの方がおられましたらご教示願います。
まだ回答がついていません
会員登録して回答してみよう