Briefly describe the scenario, such as a.component and b.component will use the following code,
import axios from 'axios';
export default(){
data(){
return {
initList: [],
pageSize: 10,
pageNo: 1
}
},
created(){
this.initList();
},
methods: {
initList(){
axios({
url: '/list1',
data: {}
})
.then(res => res.data)
.then(data => {
this.initList = data;
})
},
pageSizeChange(size){
this.pageSize = size;
this.initList();
},
pageNoChange(pageNo){
this.pageNo = pageNo;
this.initList();
}
}
}
After using this code, the two components only request different URLs when communicating. How to use mixin reuse, CaiGou please give me some advice~
The only difference you have is the url, so you can just define the url as the data attribute. Add the data attribute url to your mixin, and then define the url in the a and b components respectively, which will overwrite the url in the mixin, as follows:
mixin:
a:
b is defined in the same way as a
Put the repeated code into mixin.js, and write the non-duplicated initList() in each component separately
What I’m thinking about now is
No need to change anything else. As for judging how to write, just write it yourself based on the difference between the two pages.