Commit a6b07f75 authored by 周远喜's avatar 周远喜

插件安装,log,error捕获

parent 92334c13
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
<h1>总数:{{counter}}</h1> <h1>总数:{{counter}}</h1>
<h2>admin,user{{this.$store.state.admin.user.counter}}</h2> <h2>admin,user{{this.$store.state.admin.user.counter}}</h2>
<Button @click="increment">+</Button> <Button @click="increment">+</Button>
<Button type="error" @click="log">log</Button>
</div> </div>
</div> </div>
</div> </div>
...@@ -47,6 +48,13 @@ export default { ...@@ -47,6 +48,13 @@ export default {
},methods: { },methods: {
increment () { increment () {
this.$store.commit('increment') this.$store.commit('increment')
},
log(){
this.$log.push("这是一个错误!")
this.$log.capsule('iView', 'Success', this);
if (process.env.NODE_ENV === 'development'){
alert(123)
}
} }
} }
} }
......
...@@ -2,7 +2,10 @@ import Vue from 'vue' ...@@ -2,7 +2,10 @@ import Vue from 'vue'
import ViewUI from 'view-design' import ViewUI from 'view-design'
import VueI18n from 'vue-i18n'; import VueI18n from 'vue-i18n';
import Languages from '@/i18n/locale'; import Languages from '@/i18n/locale';
// import VueDND from 'awe-dnd' // 插件
import util from '@/libs/util';
import VueDND from 'awe-dnd' //拖拽排序
// import iViewPro from '@/libs/iViewPro/iview-pro.min.js'; // import iViewPro from '@/libs/iViewPro/iview-pro.min.js';
// import '@/libs/iViewPro/iview-pro.css'; // import '@/libs/iViewPro/iview-pro.css';
import iViewPro from '../iview-pro/src/index.js'; import iViewPro from '../iview-pro/src/index.js';
...@@ -18,9 +21,9 @@ require("../mock") ...@@ -18,9 +21,9 @@ require("../mock")
export default ({ export default ({
app, app,
store store
}) => { }) => {
Vue.use(VueI18n) Vue.use(VueI18n)
// Vue.use(VueDND) Vue.use(VueDND)
app.i18n = new VueI18n({ app.i18n = new VueI18n({
locale: 'zh-CN', locale: 'zh-CN',
messages: Languages messages: Languages
...@@ -32,6 +35,47 @@ export default ({ ...@@ -32,6 +35,47 @@ export default ({
}) })
Vue.use(iViewPro); Vue.use(iViewPro);
Vue.prototype.$log = {
...util.log,
push(data) {
if (typeof data === 'string') {
// 如果传递来的数据是字符串
// 赋值给 message 字段
// 为了方便使用
// eg: this.$log.push('foo text')
store.dispatch('admin/log/push', {
message: data
});
} else if (typeof data === 'object') {
// 如果传递来的数据是对象
store.dispatch('admin/log/push', data);
}
}
}
Vue.config.errorHandler = function (error, instance, info) {
Vue.nextTick(() => {
// store 追加 log
store.dispatch('admin/log/push', {
message: `${info}: ${error.message}`,
type: 'error',
meta: {
error
// instance
}
});
// 只在开发模式下打印 log
if (process.env.NODE_ENV === 'development') {
util.log.capsule('iView Admin', 'ErrorHandler', 'error');
util.log.error('>>>>>> 错误信息 >>>>>>');
console.log(info);
util.log.error('>>>>>> Vue 实例 >>>>>>');
console.log(instance);
util.log.error('>>>>>> Error >>>>>>');
console.log(error)
}
})
}
// Vue.directive('paste', { // Vue.directive('paste', {
// bind(el, binding, vnode) { // bind(el, binding, vnode) {
// el.addEventListener('paste', function (event) { //这里直接监听元素的粘贴事件 // el.addEventListener('paste', function (event) { //这里直接监听元素的粘贴事件
...@@ -40,4 +84,4 @@ export default ({ ...@@ -40,4 +84,4 @@ export default ({
// } // }
// }) // })
// console.warn("this:",app.i18n.locale,app) // console.warn("this:",app.i18n.locale,app)
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment