0
我正在做網頁切換非常簡單的頁面。在我需要調用@click
方法的url之一。這裏是我的代碼:如何從路由器模板調用功能?
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
。