我正在开发Vue应用程序,现在我需要使用Vue路由器。但是我在将数据绑定到路由器模板时遇到了一些小问题。请帮帮我。
HTML:
"
HTML:
<div id="app">
<h1>Hello App!</h1>
<p>
<router-link to="/foo">Go to Foo</router-link>
<router-link to="/bar">Go to Bar</router-link>
</p>
<router-view></router-view>
</div>
脚本:
const Foo = { template: '<div>{{foo}}</div>' }
const Bar = { template: '<div>bar</div>' }
const routes = [
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar }
]
const router = new VueRouter({
routes
})
const app = new Vue({
el: '#app',
router,
data: function(){
return {foo: "asdasdas"}
}
})
"
{{foo}}
绑定不起作用。
{prop1:{prop1_1:"123", prop1_2:"321"}, prop2: "asd" ..etc}
2)在重定向到新路由之前,如何集成一些ajax请求。例如,我们点击“foo”链接,在重定向之前,我们发出请求以获取要绑定的对象。 - snowil