1. ES6 重點 1-1 Array 陣列存取 1-2 String 對象方法 1-3 setTimeout 倒數計時 2. Vue 入門 2-1 響應式資料 ref、reactive及 v-model 雙向綁定 2-2 v-on 事件綁定及readonly 唯讀 2-3 v-for 迴圈、v-bind 屬性綁定、v-show及v-if、computed 2-4 watch 及 watchEffect 監聽 2-5 常用生命週期 2-6 事件修飾符 3. axios 存取資料 4. 安裝 node.js 及 vue-cli 4-1 Component 組件開發 4-2 scss 用法 5. 父組件→子組件間的參數傳遞(props) 5-1 子組件→父組件間的參數傳遞(emits) 6. transition 動畫 6-1 transition + keyframes 7. 點擊時,利用 $event 取得點擊事件及參數 8. Template Refs 模板引用 8-1 自定義模板語法 v-xx 8-2 slot 用法 9. Vue Router 9-1 配置路由 9-2 加入連結 9-3 useRoute 及 useRouter 10. Vuex 資料傳遞 10-1 拆分 Vuex 10-2 modules 用法 11. Composition API 12. 使用 Element plus 12-1 配置版面 13. 使用 websocket 14. nuxt 框架 14-1 nuxt 生命週期 14-2 後台的 asyncData 14-3 後台的 fetch 14-4 nuxt.config.js 14-5 Nuxt 使用 Router 14-6 錯誤頁面 14-7 plugin 14-7-1 注入 plugin 14-7-2 整合現有的nuxt套件 plugin 14-7-3 整合一般npm套件 plugin 14-7-4 將 localStorage 做成 plugin 14-8 使用vuex
14-7-3
整合一般npm套件 plugin
先安裝此套件 https://www.npmjs.com/package/vue-notification (要有支援SSR的套件才不會有問題)
npm install --save vue-notification
建立/plugins/notification.js
import Vue from "vue";
// for SPA:
// import Notifications from 'vue-notification'
// for SSR:
import Notifications from "vue-notification/dist/ssr.js";
Vue.use(Notifications);
加到 nuxt.config.js 設定
plugins: ["~/plugins/hello.js", "~/plugins/axios.js","~/plugins/notification.js"],
將套件載入語法<notifications group="foo" />加到每頁都會執行到的地方,如:layouts\default.vue
<template>
<div>
<Nav />
<!-- 主畫面 -->
<div class="container">
<div class="row">
<!-- 主內容區 -->
<div class="col-md-9">
<Nuxt />
<notifications group="foo" />
</div>
<!-- 側邊欄 -->
<div class="col-md-3">
<Aside />
</div>
</div>
</div>
</div>
</template>
接著加入方法
methods: {
handNotify() {
this.$notify({
group: "foo",
title: "Important message",
text: "Hello user! This is a notification!",
});
}
},
加個按鈕以呼叫該方法
<template>
<div>
<h1>關於</h1>
<button @click="handNotify">按我</button>
</div>
</template>
由於該套件的CSS是放在src/Notifications.vue中,無法被plugin讀取,所以,從中取出CSS,並另存至assets\notification.css
.vue-notification-group {
display: block;
position: fixed;
z-index: 5000;
}
.vue-notification-wrapper {
display: block;
overflow: hidden;
width: 100%;
margin: 0;
padding: 0;
}
.notification-title {
font-weight: 600;
}
.vue-notification-template {
display: block;
box-sizing: border-box;
background: white;
text-align: left;
}
.vue-notification {
display: block;
box-sizing: border-box;
text-align: left;
font-size: 12px;
padding: 10px;
margin: 0 5px 5px;
color: white;
background: #44A4FC;
border-left: 5px solid #187FE7;
}
.vue-notification.warn {
background: #ffb648;
border-left-color: #f48a06;
}
.vue-notification.error {
background: #E54D42;
border-left-color: #B82E24;
}
.vue-notification.success {
background: #68CD86;
border-left-color: #42A85F;
}
.vn-fade-enter-active, .vn-fade-leave-active, .vn-fade-move {
transition: all .5s;
}
.vn-fade-enter, .vn-fade-leave-to {
opacity: 0;
}
接著在nuxt.config.js中加入CSS設定
css: ['~/assets/notification.css'],
1. ES6 重點 1-1 Array 陣列存取 1-2 String 對象方法 1-3 setTimeout 倒數計時 2. Vue 入門 2-1 響應式資料 ref、reactive及 v-model 雙向綁定 2-2 v-on 事件綁定及readonly 唯讀 2-3 v-for 迴圈、v-bind 屬性綁定、v-show及v-if、computed 2-4 watch 及 watchEffect 監聽 2-5 常用生命週期 2-6 事件修飾符 3. axios 存取資料 4. 安裝 node.js 及 vue-cli 4-1 Component 組件開發 4-2 scss 用法 5. 父組件→子組件間的參數傳遞(props) 5-1 子組件→父組件間的參數傳遞(emits) 6. transition 動畫 6-1 transition + keyframes 7. 點擊時,利用 $event 取得點擊事件及參數 8. Template Refs 模板引用 8-1 自定義模板語法 v-xx 8-2 slot 用法 9. Vue Router 9-1 配置路由 9-2 加入連結 9-3 useRoute 及 useRouter 10. Vuex 資料傳遞 10-1 拆分 Vuex 10-2 modules 用法 11. Composition API 12. 使用 Element plus 12-1 配置版面 13. 使用 websocket 14. nuxt 框架 14-1 nuxt 生命週期 14-2 後台的 asyncData 14-3 後台的 fetch 14-4 nuxt.config.js 14-5 Nuxt 使用 Router 14-6 錯誤頁面 14-7 plugin 14-7-1 注入 plugin 14-7-2 整合現有的nuxt套件 plugin 14-7-3 整合一般npm套件 plugin 14-7-4 將 localStorage 做成 plugin 14-8 使用vuex