ZGLHHH
V2EX  ›  PHP

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

  •  
  •   ZGLHHH · Apr 23, 2016 · 3014 views
    This topic created in 3850 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
    airyland
    Apr 23, 2016
    1
    直接在 Views_Edit 加个 data () 获取数据,看文档。
    ZGLHHH
    ZGLHHH
    OP
    Apr 23, 2016
    2
    @airyland 具体地址?
    airyland
    airyland
    Apr 23, 2016❤️1
    3
    @ZGLHHH 额。。这看下文档目录就知道了吧。 http://vuejs.github.io/vue-router/zh-cn/pipeline/data.html
    ZGLHHH
    ZGLHHH
    OP
    Apr 23, 2016
    4
    @airyland 那么有什么方法能让 vuejs 实现类似于 angularjs 的 templateURL 功能?
    nnil
    nnil
    Apr 24, 2016 via Android
    5
    给 template 取个 id
    ZGLHHH
    ZGLHHH
    OP
    Apr 24, 2016
    6
    @nnil 不太懂……
    miaotaizi
    miaotaizi
    May 5, 2016❤️1
    7
    请细看 http://vuejs.github.io/vue-router/zh-cn/pipeline/data.html
    你应该在 Views_Edit 的对象中添加

    ```js

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

    ```
    miaotaizi
    miaotaizi
    May 5, 2016
    8
    大概就是这样 return 的对象 会自动赋值到当前组件的 data 上去
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1682 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 05:20 · PVG 13:20 · LAX 21:20 · JFK 00:20
    ♥ Do have faith in what you're doing.