V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ZGLHHH
V2EX  ›  PHP

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

  •  
  •   ZGLHHH · 2016-04-23 13:01:57 +08:00 · 2195 次点击
    这是一个创建于 2941 天前的主题,其中的信息可能已经有所发展或是发生改变。
    /* 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 中,再展示在用户浏览器中,请问应该怎么改?
    8 条回复    2016-05-05 13:04:47 +08:00
    airyland
        1
    airyland  
       2016-04-23 13:24:16 +08:00
    直接在 Views_Edit 加个 data () 获取数据,看文档。
    ZGLHHH
        2
    ZGLHHH  
    OP
       2016-04-23 13:35:43 +08:00
    @airyland 具体地址?
    airyland
        3
    airyland  
       2016-04-23 13:43:21 +08:00   ❤️ 1
    @ZGLHHH 额。。这看下文档目录就知道了吧。 http://vuejs.github.io/vue-router/zh-cn/pipeline/data.html
    ZGLHHH
        4
    ZGLHHH  
    OP
       2016-04-23 15:03:33 +08:00
    @airyland 那么有什么方法能让 vuejs 实现类似于 angularjs 的 templateURL 功能?
    nnil
        5
    nnil  
       2016-04-24 12:45:24 +08:00 via Android
    给 template 取个 id
    ZGLHHH
        6
    ZGLHHH  
    OP
       2016-04-24 13:22:44 +08:00
    @nnil 不太懂……
    miaotaizi
        7
    miaotaizi  
       2016-05-05 13:04:14 +08:00   ❤️ 1
    请细看 http://vuejs.github.io/vue-router/zh-cn/pipeline/data.html
    你应该在 Views_Edit 的对象中添加

    ```js

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

    ```
    miaotaizi
        8
    miaotaizi  
       2016-05-05 13:04:47 +08:00
    大概就是这样 return 的对象 会自动赋值到当前组件的 data 上去
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1753 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 16:38 · PVG 00:38 · LAX 09:38 · JFK 12:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.