前置条件
使用 runtimeCompiler 版本的Vue,即运行+编译的完整版Vue
代码示例
<template>
<div>
<basic-custom />
div>
template>
<script>
import Vue from "vue";
/**
* 子组件
*/
var myConfig = null;
let BasicCustom = Vue.component("BasicCustom", (resolve, reject) => {
// setTimeout(() => { // 可以从异步获取自定义配置
resolve({
template: `
` + myConfig.customTemplate + `
`, props: {
...myConfig.customProps,
},
data() {
return {
...myConfig.customData,
};
},
computed:{
...myConfig.customComputed,
},
watch: {
...myConfig.customWatch,
},
created() {
// 执行自定义事件中的init()
if (typeof this.init == "function") {
this.init();
}
},
methods: {
...myConfig.customMethods,
},
});
//}, 120);
});
/** *************************************** */
export default {
props: {},
components: {
BasicCustom,
},
data() {
return {};
},
watch: {
},
created() {
},
mounted() {
},
methods: {
},
};
script>
<style>style>