首页 > 其他分享 >vue-8 组件

vue-8 组件

时间:2022-10-13 11:56:13浏览次数:64  
标签:vue 按钮 组件 import goToIndex currentPageIndex

import Vue from 'vue'
//全局部引入
import ElementUI from 'element-ui'
// //按需引入
import {Row,Button} from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue'
import Global from './components/Global.vue'

Vue.config.productionTip = false


//注册Element UI
Vue.use(ElementUI)
// //按需注册
Vue.use(Row)
Vue.use(Button)

//全局组件注册,前面是组件名
Vue.component("Global",Global)

new Vue({
  render: h => h(App),
}).$mount('#app')
<template>
  <div id="app">
    <!--组件-->
    <span>-------------------------------------------------------------------------------------------------------</span><br />
    <span>【父组件】获取的当前页面组件共{{parentItemCount}}条,每页{{parentPageSize}}条,当前页号{{parentPageIndex}}</span><br />
    <span>-------------------------------------------------------------------------------------------------------</span>
    <pageDemo3 :pageSize="5" :itemCount="82" @demo3-event="myMethod" />
    <Global />  //使用全局组件

    <!--Element UI-->
    <element-uI-demo /> 
  </div>
</template>

<script>
import pageDemo3 from "./components/pageDemo3.vue";

import ElementUIDemo from './components/ElementUIDemo.vue'

export default {
  name: 'App',
  data() {
    return {
      parentItemCount: 0,
      parentPageSize: 0,
      parentPageIndex: 0,
      test: 1
    }
  },
  components: {
 
    pageDemo3,
    ElementUIDemo
  },

  methods: {
    myMethod(data) {
      this.parentItemCount = data.itemCount
      this.parentPageSize = data.pageSize
      this.parentPageIndex = data.currentPageIndex
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
<template>
  <div>
    <span>
      共 {{itemCount}} 条
      <select v-model="currentPageSize"
              @change="changePageSize">
        <option v-for="item in pageSizes"
                :key="item"
                :value="item">{{ item }}条/页</option>
      </select>&nbsp;&nbsp;
      <!--【上一页】上一页标签及v-if逻辑-->
      <a href="javascript:void(0)"
         class="pageItem"
         v-if="currentPageIndex > 1"
         @click="goPage(currentPageIndex-1)">&lt;</a>
      <span class="pageItem"
            v-if="currentPageIndex <= 1">&lt;</span>
      <!--【分页数量】中间页号标签及v-for、v-if逻辑-->
      <span v-for="page in calPageCount"
            :key="page">
        <span class="pageItem spanItem "
              v-if="page === currentPageIndex">{{page}}</span>
        <a href="javascript:void(0)"
           class="pageItem"
           v-if="page !== currentPageIndex"
           @click="goPage(page)"
           :ref="'lnk_' + page">{{ page }}</a>
      </span>
      <!--【下一页】下一页标签及v-if逻辑-->
      <a href="javascript:void(0)"
         class="pageItem"
         v-if="currentPageIndex < calPageCount"
         @click="toPage(currentPageIndex+1)">&gt;</a>
      <span class="pageItem"
            v-if="currentPageIndex >= calPageCount">&gt;</span>前往第
      <input type="text"
             v-model.number="goToIndex"
             style="width: 30px"
             @change="goToPage"
             onfocus="this.select()"/>页
    </span>
  </div>
</template>


<script>
export default {
  name: "pageDemo3",
  props: {
    pageSize: Number,
    itemCount: Number
  },
  data() {
    return {
      pageSizes: [5, 10, 15, 20],
      currentPageSize: 5,
      currentPageIndex: 1,
      goToIndex:null
    };
  },
  created() {
    this.currentPageSize = this.pageSize;
  },
  computed: {
    //计算总页数据,计算属性
    calPageCount() {
      return Math.ceil(this.itemCount / this.currentPageSize);
    }
  },
  methods: {
    changePageSize() {
      this.currentPageIndex = 1;
    },
    callback() {
      let callbackData = {
        itemCount: this.itemCount,
        pageSize: this.currentPageSize,
        currentPageIndex: this.currentPageIndex
      };
      this.$emit("demo3-event", callbackData);
    },
    goPage(num) {
      this.currentPageIndex = num;
      //回调父组件事件
      this.callback();
      this.goToIndex = null
    },
    toPage(num) {
      this.currentPageIndex = num;
      //回调父组件事件
      this.callback();
      this.goToIndex = null
    },
    goToPage(){
      if (this.goToIndex < 1) {
        this.currentPageIndex = 1;
        this.goToIndex = 1
      }else if (this.goToIndex > this.calPageCount) {
        this.currentPageIndex = this.calPageCount;
        this.goToIndex = this.calPageCount;
      }else{
        this.currentPageIndex = this.goToIndex
      }
      //回调父组件事件
      this.callback();
    }
  }
};
</script>


<style>
.pageItem {
  margin-right: 1px;
  padding: 5px 5px 5px 5px;
}

.spanItem {
  color: blue;
}
</style>
<template>
    <div id="global">
        <span style="color:red; font-size:30px;">我是一个全局组件。</span>
    </div>
</template>
<script>
export default {
    name:'Global'
}
</script>
<template>
  <div id="element-ui-demo">
    <el-row>
      <el-button>默认按钮</el-button>
      <el-button type="primary">主要按钮</el-button>
      <el-button type="success">成功按钮</el-button>
      <el-button type="info">信息按钮</el-button>
      <el-button type="warning">警告按钮</el-button>
      <el-button type="danger">危险按钮</el-button>
    </el-row>

    <el-row>
      <el-button plain>朴素按钮</el-button>
      <el-button type="primary" plain>主要按钮</el-button>
      <el-button type="success" plain>成功按钮</el-button>
      <el-button type="info" plain>信息按钮</el-button>
      <el-button type="warning" plain>警告按钮</el-button>
      <el-button type="danger" plain>危险按钮</el-button>
    </el-row>
  </div>
</template>
<script>
export default {
  name: "ElementUIDemo",
  data() {
    return {};
  },
};
</script>

 

标签:vue,按钮,组件,import,goToIndex,currentPageIndex
From: https://www.cnblogs.com/dwdw/p/16787697.html

相关文章

  • vue-directive__自定义指令
    vue-directive__自定义指令1.复制/***v-copy*复制某个值至剪贴板*接收参数:string类型/Ref<string>类型/Reactive<string>类型*/importtype{Directive,Direct......
  • Vue动态组件 表格
    Vue组件数据源//这里是HTML内容这里通过下面的引入框架结构把数据源传到框架中还有匹配项<Mytable:configList="configList":configData="configData"></Mytable>......
  • vue table表头固定,内容滚动实现
    先上效果   1<template>2<divclass="simpTable">3<table>4<thead>5<th6v-for="(item,index)oftableHe......
  • vuepress 运行报错 Vue packages version mismatch:
    vuepress运行报错Vuepackagesversionmismatch:D:\vuepress-test>npmrundocs:devnpmWARNconfigglobal`--global`,`--local`aredeprecated.Use`--location......
  • vue上传图片并生成海报
    用到的插件:vue-cropper(裁剪)  vue-canvas-poster(生成海报),最终合成海报调用裁剪插件方法getCropBlob,利用canvas画出海报。需求说明:默认有个海报缩略图展示,有模版可供......
  • React Hook:无用渲染-PureComponent-shouldCompoent-函数组件
    过渡技术1.1无用的渲染组件是构成React视图的一个基本单元。有些组件会有自己本地的状态(state),当它们的值由于用户的操作而发生改变时,组件就会重新渲染。在一个React......
  • Element UI tree组件总结
    tree组件折叠//关闭弹窗时,折叠组织树(耗时操作)for(vari=0;i<this.$refs.tree.store._getAllNodes().length;i++){this.$refs.tree.store._getAllNodes()[i......
  • Vue3组件间传值
    12种方式1.父组件./father.vue点击查看代码<template><h1>father:</h1><h3>子组件传过来的:{{abc}}</h3><inputtype="text"ref="inp"v-model="msg"......
  • Vue——前端框架
    Vue    Vue快速入门  <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>Title</title></head><body><divid="app">......
  • form-create-designer开源啦,好用的vue可视化表单设计器
    form-create-designer开源啦,好用的vue可视化表单设计器无懈可击......