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

344
Visualizações
Vue3: is it possible to import a HTML file with components in it to a SFC

I have a Form-Component (SFC) that should import a HTML file with Vue components in it.

Form-Component

<template src="../../../views/form-settings.html"></template>

<script setup>
import Button from "./../ui/button/Button.vue";
</script>

HTML File (form-settings.html)

<div>
     <Button>test button</Button>
</div>

package.json

"devDependencies": {
    "@vue/compiler-sfc": "^3.2.31",
    "laravel-mix": "^6.0.6",
    "vue-loader": "^17.0.0"
},
"dependencies": {
    "vue": "^3.2.31",
},

The HTML file gets loaded correctly but the Button-Component in it not. So I get the error: [Vue warn]: Failed to resolve component: Button If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.

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

0

I have now solved the problem myself.

I had to import the components I want to use in the HTML file in app.js and then initialize them with Vue.

import BaseButton from "./components/ui/BaseButton.vue";
app.component("BaseButton", BaseButton);
about 4 years ago · Juan Pablo Isaza Relatório

0

Yes it is possible.

You can even import the script and style section:

<template src="./template.html"></template>
<style src="./style.css"></style>
<script src="./script.js"></script>

Read it in the docs.


I don't know why your code doesn't work, I tried to create a similar demo and it works fine. See it here on Stackblitz

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