vue中对页面影响大的写到url中
2020-10-28 本文已影响0人
w_小伍
于像 page、size,keyword等参数,应该写到url中
import _get from 'lodash.get'
import _toNumber from 'lodash.tonumber'
export default {
data() {
return {
page: {
current:1,
size: 10
},
keyword: ''
}
},
watch: {
$route: {
immediate: true,
handler() {
this.page.current= _toNumber(_.get(this.$route, 'query.page', 1))
this.page.size = _toNumber(_.get(this.$route, 'query.size', 10))
this.keyword = _.get(this.$route, 'query.keyword ', '')
}
}
},
method: {
// 跳转公共方法
routerPush() {
let queryObj = {
page: this.page.current,
size: this.page.size ,
}
if (this.keyword ) { // 有值才加到url里
queryObj.keyword = this.keyword
}
this.$router.push({
name: 'libraryOfGoods',
query: queryObj
})
},
}
}