W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
Nuxt.js具有完全模塊化的架構(gòu),允許開發(fā)人員使用靈活的API擴展Nuxt Core的任何部分。
如果有興趣開發(fā)自己的模塊,請查看 Modules 教程 獲取更多詳細(xì)信息。
本節(jié)有助于熟悉Nuxt內(nèi)部,并可以作為參考,在編寫自己的模塊時更好地理解它。
這些類是Nuxt的核心,應(yīng)該在運行時和構(gòu)建時都存在。
這些類僅用于構(gòu)建或開發(fā)模式。
Nuxt默認(rèn)導(dǎo)出所有類。要導(dǎo)入它們:
import { Nuxt, Builder, Utils } from 'nuxt'
所有Nuxt類都引用了nuxt實例和選項,這樣我們總是在類之間有一致的API來訪問options和nuxt。
class SomeClass {
constructor (nuxt) {
super()
this.nuxt = nuxt
this.options = nuxt.options
}
someFunction () {
// We have access to `this.nuxt` and `this.options`
}
}
類是可插入的,因此他們應(yīng)該在main nuxt容器上注冊一個插件來注冊更多的hooks。
class FooClass {
constructor (nuxt) {
super()
this.nuxt = nuxt
this.options = nuxt.options
this.nuxt.callHook('foo', this)
}
}
所以我們可以像這樣掛載hook foo模塊:
nuxt.hook('foo', (foo) => {
// ...
})
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: