0
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 3 years have passed since last update.

Vue.jsでちょっとハマったtips

Posted at

下記構成でハマったこと。

  • vue-cliで初期化
  • vue-router導入
  • axios導入

vue.jsはvue3

ハマったこと

  • 別コンポーネントのmethodsを呼び出す方法
# BlogContents.vue
<script>
import MicroCms from '@/components/MicroCms.vue'

export default {
  name: 'Blog',
  mounted () {
    MicroCms.methods.getBlog() # この記法じゃないと呼び出せない
  }
}
</script>

# MicroCms.vue
<script>
import axios from 'axios'

export default {
  name: 'MicroCms',
  methods: {
    getBlog: function () {
      axios.get(
        // 処理
      )
    }
  }
}

BlogContents.vueからMicroCms.vuegetBlog()を呼ぶ際に下記の記法だと取得できなかった。

MicroCms.getBlog()

この記法だとgetBlog()はfunctionじゃないから見つからない的なエラーが出力される。

0
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
0
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?