Upgrade to Pro — share decks privately, control downloads, hide ads and more …

NuxtJSの色々な共通化を試してみた話

tossyyukky
October 21, 2019

 NuxtJSの色々な共通化を試してみた話

tossyyukky

October 21, 2019
Tweet

Other Decks in Programming

Transcript

  1. Export/Import class Animal { constructor(greeting) { this.greeting = greeting; }

    say() { return this.greeting; } } export default Animal; lib/Animal.js
  2. Export/Import <template> <div>{{say()}}</div> </template> <script> import Animal from ‘@/lib/Animal’ export

    default { … methods: { say() { return new Animal(‘meow meow’).say() } } } </script> page/say.vue
  3. Mixin <template> <div> <button @click=‘show()’>Show Popup</button> </div> </template> <script> import

    Popup from ‘@/mixins/popup’ export default { … mixins: [Popup], … } </script> page/use_mixin.vue
  4. Plugin class I18n { t(key) {…} } export default ({

    app }, inject) => { const i18n = new i18n(); // ίϯςΩετʹಥͬࠐΉ৔߹ app.i18n = i18n; // Ͳ͔͜ΒͰ΋࢖͍͍ͨ৔߹ inject(‘i18n’, i18n); } plugins/i18n.js
  5. Middleware export default ({ store, redirect }) => { if

    (!store.state.isLoggedIn) { redirect(‘/login’); } } middleware/auth.js