简体   繁体   English

如何为不同的当前页面调用不同的方法?

[英]How to call different methods for different current pages?

 perPage: 3, currentPage: 1, computed: { rows() { return this.productsList.length }, methods: { page() { if (this.currentPage = 2) { let accToken = localStorage && localStorage.loggedinUser? localStorage.loggedinUser: null; const categoryUrl = project_key + '/product-projections/search?offset=12&limit=12'; const sendGetRequest = async() => { let access_token = await axios.request({ method: "get", baseURL: categoryUrl, headers: { 'Authorization': "Bearer " + accToken, 'Content-Type': 'application/json', }, data: {} }).then((response) => { if (response) { // this.productsList = response.body; this.productsList = response.data.results; // eslint-disable-next-line console.log(this.productsList); } }); }; sendGetRequest(); } },
 <b-pagination v-model="currentPage":total-rows="rows":per-page="perPage" aria-controls="my-table" @change="page"></b-pagination> <p class="mt-3">Current Page: {{ currentPage }}</p>

I am using b-pagination event per-page="perPage", And i am writing method to call api.我正在使用 b-pagination 事件 per-page="perPage",并且我正在编写调用 api 的方法。

Where in perPage() i am calling if (this.currentPage = 2) {}.在 perPage() 中我调用 if (this.currentPage = 2) {} 的位置。 So my question is by using single:per-page="perPage", can i write multiple methods and change currentPage for each method?所以我的问题是通过使用 single:per-page="perPage",我可以编写多个方法并为每个方法更改 currentPage 吗?

<b-pagination 
    v-model="currentPage" 
    :total-rows="rows" 
    :per-page="perPage" 
    aria-controls="my-table" 
    @change="page"
></b-pagination>

If you look into the code.如果您查看代码。 There is @change event is listening.有@change 事件正在监听。 You need to add page() function in your methods.您需要在方法中添加 page() function。 like below像下面

methods: {
    page(event) {
        this.currentPage = event
        let offset = (this.currentPage * this.perPage)
        const categoryUrl = project_key + `/product-projections/search?offset=${offset}&limit=${this.perPage}`;
        // other logics....
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM