小编sno*_*wil的帖子

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>
Run Code Online (Sandbox Code Playgroud)

脚本:

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"}
  }
})
Run Code Online (Sandbox Code Playgroud)

{{foo}}绑定不起作用。

实例: …

javascript bind vue.js vue-router

6
推荐指数
2
解决办法
3360
查看次数

标签 统计

bind ×1

javascript ×1

vue-router ×1

vue.js ×1