<h2>{{title}}</h2>
<p>{{content}}</p>
comp.js -- 组件定义
define(['text!comp.html'], function (temp) { // 在requirejs中定义一个模块,依赖为模板文本
return {
props: ['title', 'content'],
template: temp
}
});
require.config({
paths: { // 指定text.js和vue.js的路径,不需要.js后缀,详见RequireJS文档
text: '../../../assets/requirejs/text',
vue: '../../../assets/vue/vue'
}
});
require(['vue'], function (Vue) { // 依赖vue.js
Vue.component('comp', function (resolve) { // 注册一个异步组件
require(['comp'], function (comp) { // 因为我们要按需加载组件,因此require(['comp'])必须在function里
resolve(comp)
})
});
new Vue({
el: 'body'
});
//new Vue({
// el: 'body',
// components: {
// comp: function (resolve) {
// require(['comp'], function (comp) {
// resolve(comp)
// })
// }
// }
//});
});
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <component is="comp" title="我是一个组件" content="fjkldsjfkldjsklgjks"></component> <script data-main="index" src="../../../assets/require.js"></script> </body> </html>
require.config({
paths: {
text: '../../../assets/requirejs/text',
vue: '../../../assets/vue/vue'
}
});
function conponent(name) {
return function (resolve, reject) {
require([name], function (comp) {
resolve(comp)
})
}
}
require(['vue'], function (Vue) {
Vue.component('comp', conponent('comp'));
Vue.component('comp2', conponent('comp2'));
new Vue({
el: 'body'
});
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有