Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

296
Visualizações
La función Vue3 onMounted no funciona en el paquete esm incluido con el paquete acumulativo

Incluí un componente vue3 con rollup. El componente es sencillo:

 // main.vue <template> <div> <div @click="clickDiv">{{ 1 }}</div> <div ref="divRef"></div> </div> </template> <script> import { onMounted, ref, defineComponent } from 'vue' export default defineComponent({ name: 'Vue3Component', mounted () { console.log('component mounted') // it works well }, setup() { const divRef = ref() const clickDiv = () => { console.log('divRef', divRef) // it causes some warnings } onMounted(() => { console.log('component onMounted') // it causes some warnings }) return { a: ref(1), clickDiv, divRef } }, }) </script>

y la entrada de entrada:

 // index.js import Vue3Component from './main.vue' Vue3Component.install = (app) => { app.component(Vue3Component.name, Vue3Component) } export { Vue3Component }

código de configuración acumulada:

 // rollup.config.js import resolve from '@rollup/plugin-node-resolve' import commonjs from '@rollup/plugin-commonjs' import pkg from './package.json' import external from 'rollup-plugin-peer-deps-external' import vuePlugin from 'rollup-plugin-vue' const extensions = ['.vue', '.js'] const globals = { vue: 'Vue', 'highlight.js': 'hljs', 'marked': 'marked' } export default [ { input: 'src/index.js', output: [ { name: 'VueNextMEditor', file: pkg.main, format: 'umd', globals }, { file: pkg.module, format: 'es' }, { name: 'VueNextMEditor', file: pkg.unpkg, format: 'umd', plugins: [terser()], globals } ], plugins: [ external(), vuePlugin(), resolve(), commonjs({ extensions }) ] } ]

Cuando pruebo el componente localmente con vue-cli, onMounted en la configuración no funciona. El navegador muestra un error como este:

 [Vue warn]: onMounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup(). If you are using async setup(), make sure to register lifecycle hooks before the first await statement.
 [Vue warn]: Missing ref owner context. ref cannot be used on hoisted vnodes. A vnode with ref must be created inside the render function. at <Vue3Component> at <App>

Pero mounted fuera de la función de configuración funcionará. ¿Alguien puede ayudarme a resolver este problema? Vue3Component

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Resolví el problema. Sucede porque instalo vue dos veces. Lo resolví con pnpm link

 $ cd vue3-component $ pnpm install $ cd example $ pnpm link ../node_modules/vue $ pnpm install $ pnpm serve

¡Funciona!

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda