Notice: 函数 WP_Scripts::localize 的调用方法不正确$l10n 参数必须是一个数组。若要将任意数据传递给脚本,请改用 wp_add_inline_script() 函数。 请查阅调试 WordPress来获取更多信息。 (这个消息是在 5.7.0 版本添加的。) in /data/www/appblog/wp-includes/functions.php on line 6131

Vue.js路由router-link传参以及参数获取

query

路径:http://localhost:8081/#/test?name=1

<router-link :to="{path:'/test', query: {name: id}}">跳转</router-link>

获取(id是参数):this.$route.query.id

params

路径:http://localhost:8081/#/test/1

<router-link :to="'/test/'+id">跳转</router-link>

获取(id是参数):this.$route.params.id

this.$route是一个数组,里面包含路由的所有信息

对应的RESTful路由配置:

{
  path: '/test/:id',
  name: 'test',
  meta: {
    title: '测试',
  },
  component: resolve => require(['../components/test.vue'], resolve)
}

注意:router-link中链接如果是‘/’开始就是从根路由开始,如果开始不带‘/’,则从当前路由开始

上一篇 vue-resource HTTP
下一篇 vue this.$router.push()传参