您的位置:首页 > Web前端 > Vue.js

Vue templateUrl 扩展

2020-06-29 04:43 183 查看
/**
* 扩展的 Vue 的 templateUrl 插件!
* 虽然有点未被作者的初衷, 但是灵活才是第一偶觉得啊.
* 这种方法是不支持, 单独的 $mount 的方式的.
*
* @author 拓荒者 <358279128@QQ.com>
* @beta v1.0.0
*/
Vue.use(function templateUrl(){
Vue.mixin({
beforeCreate: function _beforeCreate(){
if (
this.$options.render !== undefined ||
this.$options.template !== undefined ||
(
this.$options.templateUrl === undefined ||
typeof this.$options.templateUrl !== 'string'
)
) { return ; }

var $scope = this;

Vue.http.get(this.$options.templateUrl).then(function(response){
$scope.$options.render = Vue.compile(response.body).render;
$scope.$mount($scope.$options.el);
});
}
})
});

 

转载于:https://my.oschina.net/CocoFather/blog/794474

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: