html部分
<div class="pages">
<a
@click="getData(data.pageNum - 1)"
:class="{ default: data.pageNum == 1 }"
>上一页</a
>
<a
@click.prevent="getData(item)"
:class="{ cur: data.pageNum == item }"
v-for="item in data.pageCount"
:key="item"
>{{ item }}</a
>
<a
@click="getData(data.pageNum + 1)"
:class="{ default: data.pageNum == data.pageCount }"
>下一页</a
>
</div>
export default {
data() {
return {
data: {},
};
},
mounted() {
this.getData();
},
methods: {
getData(page = 1) {
const url = "news_select.php?pageNum=" + page;
// this.axios.get(`news_select.php?pageNum=${page}`).then((res) =>
this.axios.get(url).then((res) => {
console.log(res);
this.data = res.data;
});
},
},
<style lang="scss" scoped>
.pages {
user-select: none;
.default,
.cur {
// 不接受鼠标事件
pointer-events: none;
}
}
|