【獲取當前Url信息】
data: function() {
return {
redirect: undefined,
otherQuery: []
}
},
watch: {
$route: {
handler: function(route) {
const query = route.query
if (query) {
/** 獲取vue重定向 */
this.redirect = query.redirect
/** 獲取其餘查詢鍵值對 */
this.otherQuery = this.getOtherQuery(query)
}
},
immediate: true
}
},
methods: {
getOtherQuery(query) {
return Object.keys(query).reduce((acc, cur) => {
if (cur !== 'redirect') {
acc[cur] = query[cur]
}
return acc
}, {})
}
}
【input 焦點】
<el-input ref='username' />
this.$refs.username.focus();