-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
新增vue示例权限拦截
- Loading branch information
Showing
14 changed files
with
213 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"status": "success", | ||
"content": { | ||
"Authorization": "xxxxxx" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"status": "success", | ||
"content": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Created by ligang on 2018/5/15. | ||
*/ | ||
import Vue from 'vue' | ||
|
||
Vue.directive('auth', { | ||
// bind(el, binding, vnode) { | ||
// let {value} = binding | ||
// if(value) { | ||
// Vue.nextTick(() => { | ||
// el.parentNode.removeChild(el) | ||
// }, 0) | ||
// } | ||
// } | ||
inserted(el, binding, vnode) { | ||
let {value} = binding | ||
if(value) { | ||
el.parentNode.removeChild(el) | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,4 @@ | ||
/** | ||
* Created by ligang on 2018/1/6. | ||
*/ | ||
|
||
import index from '@/views/es6/index.vue' | ||
|
||
import myModule from '@/views/es6/my-module/person.vue' | ||
import myModule2 from '@/views/es6/my-module/person2.vue' | ||
|
||
|
||
export default { | ||
path: '/es6', | ||
component: index, | ||
children: [{ | ||
path: 'module-p1', | ||
component: myModule | ||
},{ | ||
path: 'module-p2', | ||
component: myModule2 | ||
}] | ||
} | ||
export default {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<template> | ||
<div> | ||
<el-row> | ||
<el-col :span="6" :offset="9"> | ||
<label for="username"> | ||
<el-input type="input" id="username" name="username" v-model="user.username"></el-input> | ||
</label> | ||
</el-col> | ||
</el-row> | ||
<el-row> | ||
<el-col :span="6" :offset="9"> | ||
<label for="password"> | ||
<el-input type="password" id="password" name="password" v-model="user.password"></el-input> | ||
</label> | ||
</el-col> | ||
</el-row> | ||
<el-row> | ||
<el-col :span="6" :offset="11" type="flex"> | ||
<el-button @click="login">登录</el-button> | ||
</el-col> | ||
</el-row> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import {routes} from '@/router' | ||
export default { | ||
name: '', | ||
data() { | ||
return { | ||
user: { | ||
username: '', | ||
password: '' | ||
} | ||
} | ||
}, | ||
methods: { | ||
login() { | ||
this.$request({ | ||
method: 'post', | ||
url: '/api/login', | ||
data: { | ||
...this.user | ||
} | ||
}).then(({Authorization}) => { | ||
window.localStorage.Authorization = Authorization | ||
// 获取当前用户的路由情况 | ||
this.getRouters() | ||
}) | ||
}, | ||
getRouters() { | ||
this.$request({ | ||
method: 'post', | ||
url: '/api/routers', | ||
data: { | ||
...this.user | ||
} | ||
}).then(data => { | ||
routes[1].children.push({ | ||
path: '/es6', | ||
component: resolve => require(['@/views/es6/index.vue'], resolve), | ||
children: [{ | ||
path: 'module-p1', | ||
component: resolve => require(['@/views/es6/my-module/person.vue'], resolve), | ||
},{ | ||
path: 'module-p2', | ||
component: resolve => require(['@/views/es6/my-module/person2.vue'], resolve), | ||
}] | ||
}) | ||
this.$router.addRoutes(routes) | ||
this.$router.push('/es6') | ||
}) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,65 @@ | ||
<template> | ||
<div> | ||
<child | ||
name="ligang" | ||
age="28" | ||
:address="address" | ||
:style="myStyle" | ||
@m1="m1" | ||
@click="m2" | ||
@keydown.natvie="m3"> | ||
</child> | ||
name="ligang" | ||
age="28" | ||
:address="address" | ||
:style="myStyle" | ||
@m1="m1" | ||
@click.natvie="m2" | ||
@keydown.natvie="m3"> | ||
</child> | ||
|
||
<Auth-Comp :auth="true"> | ||
<div>123</div> | ||
<span slot="abc" class="123">21221</span> | ||
<div @click="getX()">{{xxxx}}</div> | ||
</Auth-Comp> | ||
|
||
<Auth-Comp> | ||
<div>456</div> | ||
</Auth-Comp> | ||
|
||
|
||
<template v-auth="true"> | ||
<div style="background-color: #00b3ee">123</div> | ||
<span slot="abc">21221</span> | ||
<div>42343</div> | ||
</template> | ||
|
||
<div v-auth="false"> | ||
<div style="background-color: #00b3ee">456</div> | ||
</div> | ||
|
||
</div> | ||
</template> | ||
|
||
<script> | ||
import Child from './child.vue' | ||
import AuthComp from './render.vue' | ||
export default { | ||
props: [], | ||
data() { | ||
return { | ||
address: '山东省', | ||
myStyle: { | ||
color: 'red' | ||
} | ||
}, | ||
xxxx: 'xxxxx' | ||
} | ||
}, | ||
methods: { | ||
m1(event) {console.log('m1', event)}, | ||
m2(event) {console.log('m2', event)}, | ||
m3(event) {console.log('m3', event)} | ||
m3(event) {console.log('m3', event)}, | ||
getX() { | ||
console.log('xxxxx') | ||
} | ||
}, | ||
components: { | ||
Child | ||
Child, | ||
AuthComp | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script> | ||
export default { | ||
name: 'Auth-Comp', | ||
functional: true, | ||
// 增加了context来弥补缺少的实例 | ||
render: function(createElement, context) { | ||
console.log(context.slots()) | ||
let {props, children, data} = context | ||
return children | ||
if(props.auth) { | ||
return createElement('div', data, children) | ||
} else { | ||
return null | ||
} | ||
} | ||
} | ||
</script> |