0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Vue.jsのSFCでscript、template、styleを別ファイルにする

Posted at

結論

  1. ディレクトリ名をコンポーネント名にする(例:SampleComponent
    1. のディレクトリ内にindex.vuetemplate.htmlstyle.cssをそれぞれ配置する
  2. index.vueの内容を以下の様にする
@/components/SampleComponent/index.vue
<script>
// ここにスクリプトコードを書いていく
import { defineComponent } from "vue";

export default defineComponent({
    name: "sample-component", //<- 必須
});
</script>

<template src="./template.html"></template> 

<style src="./style.css" scoped></style>
App.vue
<template>
    <SampleComponent />
</template>

<script>
import { defineComponent } from "vue";
import SampleComponent from "@/components/SampleComponent"

export default defineComponent({
    components: { SampleComponent },
});
</script>

参考

ディレクトリ構造

  • 📂src
    • :clipboard:App.vue
    • 📂components
      • 📂SampleComponent
        • :clipboard:index.vue
        • :clipboard:template.html
        • :clipboard:style.css

※SFCじゃなくなってるっつーツッコミは無しで。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?