ZGLHHH
V2EX  ›  PHP

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

  •  
  •   ZGLHHH · Apr 23, 2016 · 2739 views
    This topic created in 3692 days ago, the information mentioned may be changed or developed.
    /* 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 replies    2016-05-05 13:04:47 +08:00
    airyland
        1
    airyland  
       Apr 23, 2016
    直接在 Views_Edit 加个 data () 获取数据,看文档。
    ZGLHHH
        2
    ZGLHHH  
    OP
       Apr 23, 2016
    @airyland 具体地址?
    airyland
        3
    airyland  
       Apr 23, 2016   ❤️ 1
    @ZGLHHH 额。。这看下文档目录就知道了吧。 http://vuejs.github.io/vue-router/zh-cn/pipeline/data.html
    ZGLHHH
        4
    ZGLHHH  
    OP
       Apr 23, 2016
    @airyland 那么有什么方法能让 vuejs 实现类似于 angularjs 的 templateURL 功能?
    nnil
        5
    nnil  
       Apr 24, 2016 via Android
    给 template 取个 id
    ZGLHHH
        6
    ZGLHHH  
    OP
       Apr 24, 2016
    @nnil 不太懂……
    miaotaizi
        7
    miaotaizi  
       May 5, 2016   ❤️ 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  
       May 5, 2016
    大概就是这样 return 的对象 会自动赋值到当前组件的 data 上去
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   990 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 22:18 · PVG 06:18 · LAX 15:18 · JFK 18:18
    ♥ Do have faith in what you're doing.