나는 vue 응용 프로그램을 개발 중입니다. 이제 vue 라우터를 사용해야 할 때가되었습니다. 하지만 라우터 템플릿에 데이터 바인딩에 약간의 문제가 있습니다.Vue 라우터. 데이터 바인딩
도와주세요.
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}}
바인딩이 작동하지 않습니다.
라이브 예 : 귀하의 경우 https://jsfiddle.net/xgrjzsup/4430/
감사합니다! 한 가지 더 묻습니다. 대답에 대한 희망. 1)이 경우 단순한 객체를 어떻게 사용해야합니까? 예를 들어'{prop1 : {prop1_1 : "123", prop1_2 : "321"}, prop2 : "asd"..etc}'2) 새로운 경로로 리디렉션하기 전에 일부 아약스 요청을 어떻게 통합 할 수 있습니까? 예를 들어 우리는 "foo"링크를 클릭하고 리디렉션 전에 get 객체를 바인딩하도록 요청합니다. – snowil
붉은 색은 단순한 객체가 아니므로 data()를 사용할 수 있습니다. 그러나 데이터 디코 어 경로는 어떻게됩니까? vuex없이이 작업을 수행 할 수 있습니까? – snowil