【发布时间】:2021-01-22 20:23:12
【问题描述】:
在 vue2 中很容易:
<template>
<button :class="type"><slot /></button>
</template>
<script>
export default {
name: 'Button',
props: [ 'type' ],
}
</script>
import Button from 'Button.vue'
import Vue from 'vue'
var ComponentClass = Vue.extend(Button)
var instance = new ComponentClass()
instance.$mount() // pass nothing
this.$refs.container.appendChild(instance.$el)
扩展 + 创建实例。但是在 vue3 中它已被删除。还有什么办法?
【问题讨论】:
-
为什么要以这种方式(通过 DOM 操作)而不是标准的 Vue 习惯用法(即模板或渲染函数)来实例化组件?
-
@tony19 因为它只是一个例子,真正的生产方式等待后端答案并用后端数据渲染它
标签: javascript vue.js vuejs3