先直接上代码,先是JavaScript部分,定义一个component,router,vue对象

var dashboard_vue = function (resolve, reject) {
    $.get('/dashboard/').done(function (template) {
        resolve({
            template: template,
            data: function () {
                return {}
            },
            created: function () {},
            methods: {}
        });
    });
};

var router = new VueRouter({
    routes: [
        {path: "/dashboard", component: dashboard_vue},
    ]
});

var app = new Vue({
    router: router,
    data: function () {
        return {}
    },
    created: function () {},
    methods: {}

}).$mount("#app");

下面是html模版

<div class="ui main grid container content">
    <h1 class="ui header">Dashboard</h1>
</div>

这样就可以在dashboard_vue component 实例化的时候动态的去sever端请求模版,好处是不用一次性加载全部的模版,同时可以在服务端对模版做一次渲染,前后端都能够渲染的情况下,很多功能实现起来会更加灵活

标签: javascript, vue

添加新评论