Answer the question
In order to leave comments, you need to log in
Why doesn't the single-file component work?
Specified type="module" in JS file connection
Component
<template>
<div>
<p class="single-file-component">{{txt}}</p>
</div>
</template>
<script>
export default{
name: 'componentName',
data: function(){
return{
txt: 'Текст файлового компонента'
}
}
}
</script>
import Vue from 'vue'
import componentName from './components/template.vue'
Vue.component('file-component', componentName)
Answer the question
In order to leave comments, you need to log in
You are confusing warm with soft.
ES-modules is a standard javascript
and works with .js
. .vue
He doesn't know about any . You can't just write module
and expect it to work.
For single-file components, an assembly is needed anyway. Collectors use loader
's, which actually do all the magic. When you write
import componentName from './components/template.vue'
the collector finds a special loader
for in the config .vue
and launches it, it processes the file and produces a valid one as a result js
, which, in turn, is imported. Outside of faucets, in a pure browser, support for loader
's is (yet?) non-existent.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question