vue 項(xiàng)目引入echarts 添加點(diǎn)擊事件操作
main.js中
import echarts from ’echarts’
Vue.prototype.$echarts = echarts
vue文件中
_this.calendarChart=_this.$echarts.init(document.getElementById(’earlyWarningCalendar’))_this.calendarChart.on(’click’,function (param) { console.log(param)}) _this.calendarChart.setOption(_this.scatterOption)
console結(jié)果
補(bǔ)充知識(shí):vue根據(jù)路由守衛(wèi),判斷用戶權(quán)限,進(jìn)行路由跳轉(zhuǎn)
判斷用戶權(quán)限,可以說(shuō)是每一個(gè)項(xiàng)目都會(huì)用到的,因此,提供給大家較為簡(jiǎn)單的方法。
主要思想是通過(guò)判斷用戶登錄后,根據(jù)后臺(tái)返回的對(duì)應(yīng)用戶權(quán)限去驗(yàn)證用戶是否可以進(jìn)行相關(guān)的操作。
第一步,創(chuàng)建路由
提供部分代碼,用于解釋
{ path: ’/’, redirect: ’/login’, }, { path: ’/login’, name: ’login’, component: Login, }, { path: ’/front/index’, name: ’frontIndex’, component: () => import(’../views/frontDeskPage/index.vue’), meta: { isLogin: true, roles: [’0’],//定義登錄的用戶權(quán)限 }, }
注意:
meta對(duì)象中的isLogin表示需要用戶登錄后才能訪問(wèn)相應(yīng)頁(yè)面
meta對(duì)象中的roles表示用戶登錄后所帶有的權(quán)限
第二步,使用beforeEach方法
router.beforeEach((to,from,next)=>{ //console.log(to.meta.isLogin) if(to.meta.isLogin){ //判斷頁(yè)面是否需要登錄才可操作 if(store.state.user.userName){//判斷用戶是否登錄,值為true,代表登錄了 if(to.meta.roles.indexOf(String(store.state.user.power)) >= 0){//判斷登錄用戶的權(quán)限是否滿足meta對(duì)象中的roles的要求 next() }else { alert(’您沒(méi)有權(quán)限進(jìn)入頁(yè)面!’) router.push(’/login’) } }else { alert(’請(qǐng)登錄之后再操作!’) router.push(’/login’) } }else { next() }})
注意:
1、to,from,next三者分別代表,要去的頁(yè)面、當(dāng)前的頁(yè)面、下一步
2、store.state.user.userName、store.state.user.power為vuex中登錄請(qǐng)求成功后,所保存的用戶信息,書(shū)寫(xiě)時(shí)需要注意路徑是否一致
3、to.meta.roles.indexOf(String(store.state.user.power),用于比對(duì)用戶權(quán)限是否存在于meta.roles中,需要注意的是在vuex存儲(chǔ)的數(shù)據(jù)類型與meta.roles中的數(shù)據(jù)類型是否一致,如不一致需要進(jìn)行類型轉(zhuǎn)換
以上這篇vue 項(xiàng)目引入echarts 添加點(diǎn)擊事件操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 使用 kind 和 Docker 啟動(dòng)本地的 Kubernetes環(huán)境2. idea設(shè)置自動(dòng)導(dǎo)入依賴的方法步驟3. 解決python中import文件夾下面py文件報(bào)錯(cuò)問(wèn)題4. XML入門(mén)精解之結(jié)構(gòu)與語(yǔ)法5. ASP基礎(chǔ)入門(mén)第八篇(ASP內(nèi)建對(duì)象Application和Session)6. IntelliJ IDEA設(shè)置編碼格式的方法7. IntelliJ IDEA設(shè)置默認(rèn)瀏覽器的方法8. idea自定義快捷鍵的方法步驟9. IntelliJ IDEA設(shè)置條件斷點(diǎn)的方法步驟10. Idea如何去除Mapper警告方法解析
