sfc 字符串注册为组件 #7310
Unanswered
yangzhenfeng1994
asked this question in
Help/Questions
sfc 字符串注册为组件
#7310
Replies: 1 comment
-
demo |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
您好,我们现在有一个需求,要把一个vue sfc setup的字符串注册为vue上的全局组件来使用,类似于下面这样,然后在其他页面内使用,请问怎么才能把一个字符串类型的sfc文件的定义注册为一个全局组件呢?
// sfc 字符串
<template>
<script setup>
let num = $ref(0)
</script>
// 注册成全局组件
import { createApp } from 'vue'
const app = createApp(App)
app.component('customComp', {
template: ' <div>{{num}}<\div>',
data () {
return {
num: 0
}
}
})
// 其他页面使用
<compoment is='customComp'>
Beta Was this translation helpful? Give feedback.
All reactions