Vue 3 相当于 Vue.extend()

问题描述 投票:0回答:1

我正在尝试从 vue2 迁移到 vue3 下一段代码: Vue2 到 vue3 选项 api 3party纯js库中使用的其他函数回调中的代码

 const cls = Vue.extend(extendComponent);
 const instance = new cls({
      data: {
         obj: data,
         toolkit: toolkit,
         surface: surface,
         vertex: node
      },
      parent: parentComponent
                            
});
instance.$mount();

instance.$el._ref = instance;
return instance.$el;

有什么想法吗?提前非常感谢!

我尝试使用createVNode和defineComponent但不成功

vue.js vuejs3 vue-component
1个回答
0
投票

在 Vue3 中你不需要它。

一个小例子:

// Vue2
export default Vue.extend({
  name: 'FormViewer',
  components: {
    Button
  },
  props: {
    data: {
      type: String,
      default: ''
    },
    editMode: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      stringData: ''
    }
  }
}
// Vue3
<script setup>
import { ref } from 'vue';
import Button from '@/components/button';

defineProps({
 data: {
   type: String,
   default: ''
 },
 editMode: {
   type: Boolean,
   default: false
 }
})

const stringData = ref('');
</script>
© www.soinside.com 2019 - 2024. All rights reserved.