### 在应用中设置
* 创建mixin ,挂载 beforeRouteLeave 钩子函数
### **Example**
~~~
const mixin = {
data(){
return{
isBack:false
}
},
computed:{
defaultPointer() {
return this.$store.getters.position[this.$route.name] ? this.$store.getters.position[this.$route.name]['xpath'] : false
//通过vuex获取存储的xpath
}
},
beforeRouteLeave(to, from, next) {
this.$service.pointer && this.$store.dispatch('pushPosition', {
name: from.name,
position: this.$service.getPointerPosition() || false
}) //使用vuex 记录 焦点位置
if (this.isBack) {
this.$store.dispatch('pushPosition', {name: from.name, position: false}) //如果是返回操作,则设置焦点为false
}
this.$service.clear() //离开后清除已经绑定的组件
next();
},
methods: {
serviceBack() { //epg 示例默认绑定的back方法
this.isBack = true
if (this.back) {
this.back()
} else {
this.$router.go(-1)
}
}
},
}
export default Common {
name: "Common",
mixins: [mixin],
}
// 页面继承 Common
export default {
name: 'home',
extends: Common,
methods:{
back(){
this.$route.go(-1) //按下返回
}
},
mounted(){
let el = this.defaultPointer // 继承了Common的computed,可以直接获取 defaultPointer
this.$service.move(el) //移动到记录焦点
}
}
~~~