Laravel && Vue.js 路由视图问题

2016 年 4 月 23 日
 ZGLHHH
/* Application Router */
var Views_Edit = Vue.extend({
template: 'test'
})

var App = Vue.extend({})
var router = new VueRouter()
router.map({
'/user/edit': {
component: Views_Edit
}
})
router.start(App, '#app')

/* Application Router END */



这是目前的路由代码,我想把它改成用 vue-resource 请求 /user/api/edit 获取视图数据,然后赋值到 Views_Edit 的 template 中,再展示在用户浏览器中,请问应该怎么改?
2919 次点击
所在节点    PHP
8 条回复
airyland
2016 年 4 月 23 日
直接在 Views_Edit 加个 data () 获取数据,看文档。
ZGLHHH
2016 年 4 月 23 日
@airyland 具体地址?
airyland
2016 年 4 月 23 日
@ZGLHHH 额。。这看下文档目录就知道了吧。 http://vuejs.github.io/vue-router/zh-cn/pipeline/data.html
ZGLHHH
2016 年 4 月 23 日
@airyland 那么有什么方法能让 vuejs 实现类似于 angularjs 的 templateURL 功能?
nnil
2016 年 4 月 24 日
给 template 取个 id
ZGLHHH
2016 年 4 月 24 日
@nnil 不太懂……
miaotaizi
2016 年 5 月 5 日
请细看 http://vuejs.github.io/vue-router/zh-cn/pipeline/data.html
你应该在 Views_Edit 的对象中添加

```js

route: {
data: function (transition) {
return {propsData: data}
}
}

```
miaotaizi
2016 年 5 月 5 日
大概就是这样 return 的对象 会自动赋值到当前组件的 data 上去

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/273848

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX