vue 使用 runtimeCompiler 版本(运行+编译的完整版),异步动态加载自定义组件,加载第三方 template 模板和 methods 方法
前置条件
使用 runtimeCompiler 版本的 Vue,即运行+编译的完整版 Vue
代码示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| <template> <div> <basic-custom /> div> template> <script> import Vue from "vue";
var myConfig = null; let BasicCustom = Vue.component("BasicCustom", (resolve, reject) => { resolve({ template: ` ` + myConfig.customTemplate + ` `, props: { ...myConfig.customProps, }, data() { return { ...myConfig.customData, }; }, computed:{ ...myConfig.customComputed, }, watch: { ...myConfig.customWatch, }, created() { if (typeof this.init == "function") { this.init(); } }, methods: { ...myConfig.customMethods, }, }); });
export default { props: {}, components: { BasicCustom, }, data() { return {}; }, watch: { }, created() { }, mounted() { }, methods: { }, }; script> <style>style>
|