0
私は非常に単純なページをURLの切り替えとしています。 URLの1つでは、@click
メソッドに電話する必要があります。ここに私のコードです:ルーターテンプレートから関数を呼び出す方法は?
const NotFound = { template: '<p>Page not found</p>' }
const Home = { template: '<p>home page</p>' }
const Faq = { template: '<p>Faq page</p>' }
const Book = { template: `
<div>
<button @click="foo()">test</button>
</div>
` }
const routes = [
{path: '/', component: Home},
{path: '/book', component: Book},
{path: '/faq', component: Faq}
]
const router = new VueRouter({
routes // short for `routes: routes`
})
new Vue({
el: '#app',
router,
data: {
},
methods:
{
foo()
{
console.log("ffffff");
}
}
})
しかし、私はエラーが発生します:Property or method "foo" is not defined on the instance but referenced during render
。