Skip to content

Commit

Permalink
vue-notifications mini-toastr
Browse files Browse the repository at this point in the history
notifications
  • Loading branch information
wangzhao committed Aug 1, 2018
1 parent 2edc04b commit 013caca
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 34 deletions.
53 changes: 32 additions & 21 deletions 1.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
exports.hello = '18';
// exports.hello = '18';

// console.log(module);
// console.log(process);
// // console.log(module);
// // console.log(process);

const EventEmitter = require('events');
// const EventEmitter = require('events');

const myEmitter = new EventEmitter();
// const myEmitter = new EventEmitter();

myEmitter.once('newListener', (event, listener)=>{
console.log(event, listener);
if(event == 'event') {
myEmitter.on('event', ()=>{
console.log("B");
});
}
});
// myEmitter.once('newListener', (event, listener)=>{
// console.log(event, listener);
// if(event == 'event') {
// myEmitter.on('event', ()=>{
// console.log("B");
// });
// }
// });

myEmitter.on('event', ()=>{
console.log('A');
});
// myEmitter.on('event', ()=>{
// console.log('A');
// });

myEmitter.emit('event');
// myEmitter.emit('event');

console.log(EventEmitter.listenerCount(myEmitter, 'event'));
myEmitter.setMaxListeners(12);
console.log(myEmitter.getMaxListeners());
console.log(myEmitter.eventNames());
// console.log(EventEmitter.listenerCount(myEmitter, 'event'));
// myEmitter.setMaxListeners(12);
// console.log(myEmitter.getMaxListeners());
// console.log(myEmitter.eventNames());

var miniToastr = require('mini-toastr');

const toastTypes = {
success: 'success',
error: 'error',
info: 'info',
warn: 'warn'
};

miniToastr.init({ types: toastTypes });

miniToastr.success({ message: 11 })

5 changes: 4 additions & 1 deletion nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ module.exports = {
'normalize.css',
'@/less/index.css'
],
plugins: ['~/plugins/axios.js'],
plugins: [
'~/plugins/axios.js',
{ src: '~/plugins/vue-notifications.js', ssr: false }
],
// mode:'spa',
generate: {
dir: 'cdn',
Expand Down
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
"jquery": "^3.2.1",
"jsdom": "^11.11.0",
"less-loader": "^4.1.0",
"mini-toastr": "^0.8.1",
"node-less": "^1.0.0",
"normalize.css": "^8.0.0",
"request": "^2.87.0",
"vue": "^2.5.16",
"vue-notifications": "^0.9.0",
"vuex": "^3.0.1",
"xmlhttprequest": "^1.8.0"
}
Expand Down
Binary file added public/assets/apple_hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/less/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ ul li {
list-style: none;
text-align: left;
}
.mini-toastr {
right: 50% !important;
}
3 changes: 3 additions & 0 deletions public/less/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ body{
ul li{
list-style: none;
text-align: left;
}
.mini-toastr{
right: 50%;
}
2 changes: 1 addition & 1 deletion public/middleware/authenticated.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function ({ store, redirect }) {
// console.log(store);
console.log(store.state);
// console.log(store.state);
if (!store.state.authenticated) {
// return redirect('/login');
}
Expand Down
34 changes: 24 additions & 10 deletions public/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<div>
<div class="container">
<div class="left">
<h2><nuxt-link to="/">Players</nuxt-link></h2>
<h2>
<nuxt-link to="/">Players</nuxt-link>
</h2>
<ul class="players">
<li v-for="user in users" :key="user.id">
<nuxt-link :to="'/'+ user.id">{{user.name}}</nuxt-link>
Expand All @@ -18,7 +20,9 @@
<br>
<nuxt-link to="/secret">Go to secret</nuxt-link>
<br>
<button @click="alertLog">{{$store.state.count}}</button>
<button @click="alertLog">notifications me</button>
<br>
<button @click="showLoginError">{{$store.state.count}} notifications me</button>
<div>{{content_two}}</div>
<ul>
<li v-for="(key, value) in content" :key="value">{{value}} : {{key}}</li>
Expand All @@ -33,16 +37,10 @@ import Loading from '~/components/loading.vue'
import img from '@@/public/assets/tou.jpg'
// import axios from '@/plugins/axios';
import axios from 'axios';
import { resolve } from 'url';
import j1 from '@@/JSON_1.json';
export default {
// fetch({store, params}){
// return axios.get("http://my-api/stars").then(res => {
// // store.commit('setStars', res.data);
// });
// },
data() {
console.log(this);
return {
title: img,
content: null,
Expand All @@ -52,7 +50,20 @@ export default {
},
created() {
},
notifications: {
showLoginInfo: {
title: 'Welcome!',
message: 'Hello from nuxt.js',
type: 'warn',
timeout: 1000000000,
},
showLoginError: {
title: 'Welcome!',
message: 'Hello from nuxt.js',
type: 'error',
timeout: 1000000000
}
},
components: {
AppLogo,
Expand Down Expand Up @@ -104,6 +115,9 @@ export default {
methods: {
alertLog() {
this.showLoginInfo();
console.log(this);
this.$store.commit('increment')
}
}
Expand Down
2 changes: 1 addition & 1 deletion public/pages/index/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script>
export default {
validate({params, query, store}){
console.log(params, query, store);
// console.log(params, query, store);
return !isNaN(params.id);
},
asyncData({ params, env }) {
Expand Down
46 changes: 46 additions & 0 deletions public/plugins/vue-notifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import Vue from 'vue';
import VueNotifications from 'vue-notifications';
import miniToastr from 'mini-toastr';
import warnIcon from '~/assets/apple_hover.png';

const toastTypes = {
success: 'success',
error: 'error',
info: 'info',
warn: 'warn'
};

// This step requires only for mini-toastr, just an initialization
miniToastr.init({
types: toastTypes,
// style: {
// 'mini-toastr':{
// left:'50%'
// },
// 'mini-toastr__notification': {
// 'mini-toastr-notification__message': {
// 'border-radius': '5px',
// 'color': 'red'
// }
// }
// }
});
miniToastr.setIcon('error', 'i', {'class': 'fa fa-warning'})
miniToastr.setIcon('info', 'i', {'class': 'fa fa-info-circle'})
miniToastr.setIcon('success', 'i', {'class': 'fa fa-check-circle-o'})
miniToastr.setIcon('warn', 'img', {src: warnIcon, style: 'vertical-align: bottom;'})

function toast({ title, message, type, timeout, cb }) {
return miniToastr[type](message, title, timeout, cb);
}

const options = {
success: toast,
error: toast,
info: toast,
warn: toast
};

Vue.use(VueNotifications, options);


0 comments on commit 013caca

Please sign in to comment.