2
0

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】メソッドや、関数だけ別コンポーネントに切り出して共通化して使用する

Last updated at Posted at 2022-01-26

呼び出す方法

外部に切り出した関数を以下に定義

ExternalFunc.vue
<script>
  export function externalFunc() {
    return "お前なんかに折れるもんか…ドクロのマークは信念の象徴なんだぞォ";
  }
</script>

外部の関数を使用するコンポーネントが以下

CardForm.vue
<script setup lang="ts">
import { externalFunc } from "../components/ExternalFunc.vue"

function useFunc() {
  console.log(externalFunc()) // 外部の関数を呼び出し => お前なんかに折れるもんか…ドクロのマークは信念の象徴なんだぞォ
}
</script>
2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?