跳至主內容區

XOOPS輕鬆架

:::

主內容區域

選擇後會自動跳轉頁面

14-7-1 注入 plugin

  1. plugin用法,先在 plugins 下建立一個 js 檔,如:plugins/hello.js
    export default ({ app }, inject) => {
      // 注入 $hello(msg) in Vue, context and store.
      inject('hello', msg => console.log(`Hello ${msg}!`))
    }
    

     

  2. 接著修改nuxt.config.js,加入該plugin:
    export default {
      plugins: ['~/plugins/hello.js']
    }
    

     

  3. 使用方法,前端用 this.$外掛名稱,後端用$外掛名稱,如:
    export default {
      mounted() {
        this.$hello('我在前端被mounted了')
      },
      asyncData({ app, $hello }) {
        $hello('我在後端被asyncData了')
      }
    }
    

     

  4. 後端用這樣也行
    asyncData(context) {
      context.$hello('我在後端被asyncData了')
    },

     

選擇後會自動跳轉頁面

:::

左邊區域內容

書籍目錄

展開 | 闔起

快速登入


右邊區域內容

請掃此 QR Code 可連至此頁面

計數器

今天: 2064206420642064
昨天: 1840184018401840
總計: 9342275934227593422759342275934227593422759342275

頁尾區域