vue多种小功能

本文介绍了Vue.js结合Element UI及ES6实现的一些实用技巧,包括滚动到底部自动加载内容、新条目输入框自动聚焦、打开新窗口页面、Element Table 序号排列、文件上传功能实现,以及自定义方法配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

vue+element+es6

  1. 滚轮到最底部
  2. 添加新一条数据,input框自动获得焦点
  3. 打开新窗口页面
  4. elelment table 序号排列
  5. 资料文件上传
  6. this.reload() 方法配置

 

1.滚轮到最底部

this.$nextTick(() => {
     document.documentElement.scrollTop = 10000;
})

2.添加新一条数据,input框获得焦点  https://www.jianshu.com/p/63bfbbbd1e82

根据 ref 动态增加状态值。ref有值就会获得焦点,没有就不会。
<el-col :span="13" class="padding_left">
    <div class="grid-content">
     <el-input v-model="q.describe" class="paper_name" :ref="q.inputFocus"></el-input>        </div>
</el-col>
addQueastion: function(){
      // 添加新数据之前清除之前数据的 inputFocus 状态
     this.qustion.forEach(function(item){
            item.inputFocus = "";
     })
     let quest = {
            describe: "",
            percent: 1,
            checked: true,
            inputFocus: "inputFocus"
     }
     this.qustion.push(quest);
     this.$nextTick(() => {
           // 控制滚轮到底部
           document.documentElement.scrollTop = 10000;
           // 新增加的问题第一个input获得焦点
           this.$refs.inputFocus[0].$el.querySelector('input').focus()
     })
},

3.打开新窗口页面

const {href} = this.$router.resolve({
       name: "pydt",
       params: {
               id: id,
               studentStatus: 0
       }
});
window.open(href, '_blank');

解决办法①: 

window.open(window.location.origin + '/#/pydt?id='+id)

解决办法②:

window.open(window.location.origin + '/#/pydt/'+id)

vue 传参:

children: [
            {path: '/mydct', name: '满意度出题', iconCls: 'iconfont ele-icon-third-bangzhu1' , component: () => import('../views/admin/mydct.vue')},
        ]
this.$router.push({ path: '/pytpct', query: {id: util.encrypt(id)} });
this.$route.query.id

children: [
            {path: '/mydct/:id', name: '满意度出题', iconCls: 'iconfont ele-icon-third-bangzhu1' , component: () => import('../views/admin/mydct.vue')},
        ]
this.$router.push({ name: 'pytpct', params: {id: util.encrypt(id)} });
this.$route.params.id

4.elelment table 序号排列:

方法一:

方法二:

5.资料文件上传

<el-input v-model="submitPaper.fileUpload.value" class="input_file" :disabled="true"></el-input>
       <el-upload
       class="upload-demo"
       :show-file-list= "false"
       ref="upload"
       :action="submitPaper.fileUpload.doUpload"            
       :data="submitPaper.fileUpload.param" 
       :before-upload="beforeUpload"
       :on-success = 'handleSuccess'
       :on-change="changeFile"
       :auto-upload="false">
       <el-button>选择</el-button>
</el-upload>
fileUpload: {
      value: "",
      fileList: [],
      doUpload:'/api/up/file',
      param:{
           srid:''
      }
}
// 文件上传
changeFile(file, fileList) {
      this.submitPaper.fileUpload.value = file.name;
},     
beforeUpload: function(file){
      console.log(file)
},
handleSuccess(res,file,fileList){
      console.log(res)
      console.log(file,fileList)
},

show-file-list : 上传文件列表展示与否 boolean   

:action : 上传地址

:data   :上传地址的参数

:on-change: 本地上传文件信息

异步上传: this.$refs.upload.submit();

6.this.reload() 方法配置

主页面配置:

其他组件引用:

使用reload方法时,直接: this.reload() 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值