最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue+iview分頁組件的封裝

 更新時間:2020年11月17日 11:56:48   作者:wangjinsheng593  
這篇文章主要為大家詳細介紹了vue+iview分頁組件的封裝,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

vue+iview的分頁組件封裝

1.在components中創(chuàng)建pagination文件夾,接著創(chuàng)建src,index.js,index.less文件

2.index.less文件

//需要修改的樣式
.ivu-page-options {
 margin-left: 10px;

 .ivu-page-options-sizer {
  margin-right: 0;
 }
 }

3.index.js文件

import "./index.less";
import component from "./src/main";

/* istanbul ignore next */
component.install = function (Vue) {
 Vue.component(component.name, component);
};

export default component;

4.src文件夾中的main.vue

<template>
 <!-- 分頁組件 -->
 <Page
 class="saas-pagination"
 ref="page"
 :loading="loading"
 :disabled="disabled"
 :total="total"
 :show-sizer="sizer"
 :show-elevator="elevator"
 :current="params.page"
 :page-size="params.rows"
 :page-size-opts="sizeOpts"
 @on-change="currentChange"
 @on-page-size-change="pageChange"/>
</template>

<script>
export default {
 props: {
 loading: {
  type: Boolean,
  default: false
 },
 total: {
  // 數(shù)據(jù)總數(shù)
  type: [String, Number],
  default: 0
 },
 page: {
  // 當(dāng)前分頁
  type: [String, Number],
  default: 1
 },
 rows: {
  // 每頁顯示多少條
  type: [String, Number],
  default: 10
 },
 disabled: {
  type: Boolean,
  default: false
 },
 sizer: {
  // 是否顯示下拉組件
  type: Boolean,
  default: false
 },
 elevator: {
  // 是否顯示跳轉(zhuǎn)輸入框
  type: Boolean,
  default: false
 }
 },
 watch: {
 page (to) {
  this.params.page = to;
 },

 rows (to) {
  this.params.rows = to;
 }
 },
 data () {
 return {
  sizeOpts: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
  params: {
  page: 1,
  rows: 10
  }
 }
 },
 methods: {
 // 分頁改變
 currentChange (current) {
  this.params.page = current;
  this.onChange();
 },
 // 每頁顯示條數(shù)改變
 pageChange (rows) {
  this.params.page = 1;
  this.params.rows = rows;
  this.onChange();
 },

 onChange () {
  this.$emit("on-change", JSON.parse(JSON.stringify(this.params)));
 },

 reset () {
  this.params = {
  page: 1,
  rows: 10
  }
  this.onChange();
  // 當(dāng)前頁碼還原
  // this.$refs.page.currentPage = 1;
 }
 }
}
</script>

5.在components中創(chuàng)建index.js,用于全局引入

import GlobalPage from "@/components/pagination/index.js";
export default (Vue) => {
 Vue.component("GlobalPage ", GlobalPage );
}

6然后在全局的main.js引入,可全局使用

import components from "@/components/index.js";
Vue.use(components)

7.組件的使用

<template>
 <div>
  <global-page 
  ref="pagination"
  :sizer="true"
  :page="formData.page"
  :rows="formData.rows"
  :total="total"
  @on-change="pageChange">
  </global-page>
 </div>
</template>
<script>
export default {
 data(){
 return {
  total: 0, // 數(shù)據(jù)總數(shù)
  queryForm:{},
  formData: {
   page: 1,
   rows: 10,
  }
  }
 },
 methods: {
  // 分頁切換
 pageChange (params) {
  this.queryForm.page = params.page
  this.queryForm.rows = params.rows
  //查詢數(shù)據(jù)的方法
  this.search(this.queryForm)
 },
 }
}

</script>

關(guān)于vue.js組件的教程,請大家點擊專題vue.js組件學(xué)習(xí)教程進行學(xué)習(xí)。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

汝阳县| 招远市| 交城县| 昌平区| 清涧县| 禄丰县| 临沭县| 响水县| 峨山| 景宁| 壤塘县| 治多县| 阳谷县| 泾阳县| 吉木乃县| 周口市| 益阳市| 广平县| 丰原市| 西平县| 东乌珠穆沁旗| 宁都县| 武义县| 辉南县| 虹口区| 车致| 沾益县| 襄城县| 横峰县| 图片| 张家界市| 通榆县| 读书| 涡阳县| 个旧市| 萨迦县| 共和县| 石门县| 定结县| 沁水县| 长丰县|