iT邦幫忙

2021 iThome 鐵人賽

DAY 11
1
自我挑戰組

新手遇上Vue.js系列 第 28

Day28 plugin

在專案中我們常常需要擴充功能,因此我們就可以使用插件,所以今天我們就要來學習如何使用

如何使用
可以透過使用Vue.use()全域註冊的方法使用插件
https://ithelp.ithome.com.tw/upload/images/20211012/20140076Ke2kCdrdKM.png
https://ithelp.ithome.com.tw/upload/images/20211012/20140076Qci1igmI9S.png
當然我們也可以傳入其他已經寫好的的插件
https://ithelp.ithome.com.tw/upload/images/20211012/20140076aVwn9AqRqE.png
Vue.use會自動阻止多次觸發同一插件,在多次的觸發下,他只會安裝一次
小提醒:雖然Vue.js官方提供的套件像是vue-router可以自動使用Vue.use()可以做為全域使用,但在CommomJS的環境中仍是需要使用Vue.use()

製作插件
https://ithelp.ithome.com.tw/upload/images/20211012/2014007699Cx79N21D.png

參考資料: https://vuejs.org/v2/guide/plugins.html


上一篇
Day27 slot
下一篇
Day29 Mixin
系列文
新手遇上Vue.js30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言