记录一下在使用Vue和Element做项目时遇到过的难点。。。

1、在 <el-table>表格中嵌入 select下拉选择框,以及 tooltip提示框的使用

主要定义格式如红色标记代码

riderPlanListTableData : 是用来填充表格的数据

type='index' 是对每行都做个序号标记,方便取单行数据以及给单行数据赋值

特别说明一下这个 slot-scope="scope" :这个能定位到行数据,表格中有很多行时,需要通过scope.row去定位行数据 和index一起使用

          <el-table
:data="riderPlanListTableData"
stripe
border
type="index"
fit
style="width: 100%"
@select-all='selectAll'
@select="handleSelect">
<el-table-column
prop="careerLevelList"
label="产品">
<template slot-scope="scope"> <!-- scope.row.riderCGroupName 其中riderPlanListTableData中的属性-->
<el-select v-model="scope.row.riderCGroupName" placeholder="产品" clearable class="filter-item" @change="prdnameChange(scope.$index, scope.row)" style="width: 420px" >
<el-option v-for="(item,index) in scope.row.careerLevelList" :key="index" :label="item.riderCName+'-'+item.riderEName" :value="item.riderCode+'_'+item.careerLevel" />
  <!-- 当 循环的key定义为index时,会自动取出每一条 能避免key重复的问题 -->
</el-select>
<el-input v-model='scope.row.riderType' type='hidden' class="filter-item"/> <!-- 设定一个隐藏的input框,因为后面需要用到这个riderType值 >
</template>
</el-table-column>

<el-table-column
prop="sumassured"
label="额度">
<template slot-scope="scope"> <!-- el-tooltip 这个是在当前输入框中加上提示信息,可以通过在content前面加 : 冒号,动态填充tooltip需要提示的值 -->
<el-tooltip class="item" effect="dark" :content="sumassuredTips" placement="top">
<el-input v-model="scope.row.sumassured" @change="sumassuredChange(scope.$index, scope.row)" @focus="sumassuredFocus(scope.row)" class="filter-item"/>
</el-tooltip>

</template>
</el-table-column>
          <el-table-column
            prop="premiumperyear"
            label="每年保费">
          <template slot-scope="scope">
            <el-input v-model='scope.row.premiumperyear' disabled="true" class="filter-item"/> <!-- <el-input v-model='scope.row.prepaidTips' type="hidden" class="filter-item"/> -->
          </template>
        </el-table-column>
           </el-table>

响应表格中的额度输入框onFocus的方法:sumassuredFocus(scope.row)  : 这个scope.row可以取到表格中当前行所有的列数据 

/** 附加产品保额的focus焦点获取事件,提示用户当前产品的保额限定值 */
sumassuredFocus(row){  
  if(row.maxSumAssured == 0 && row.maxSumAssured == row.minSumAssured){
    this.sumassuredTips = '固定保费附加产品,无需输入保额直接选中即可!'
  }else{
    this.sumassuredTips = '最低保额:'+ row.minSumAssured + ' - 最高保额:' + row.maxSumAssured
  }
},

响应表格中的onchange方法:sumassuredChange(scope.$index,scope.row): index可以定位行序号,row可以定为当前行数据

let 和 var:  let 定义的是局部变量,var 定义的是全局变量

this.$set(this.inputForm,'attribute','attributeValue');  //通过这句话可以给this.inputForm对应的属性赋值

    /**附加产品保额变化的change事件:计算出对应的保费 */
sumassuredChange(index,row) {
let inputForm = this.inputForm;
this.tmpSplit = (row.riderCGroupName).split('_');
this.$set(this.inputForm,'riderCode','1234'); //如果this.inputForm对象中有riderCode属性,1234则会覆盖riderCode属性值,如果没有则会创建一个riderCode属性并且赋值为1234
this.$set(this.inputForm,'careerLevel',this.tmpSplit[1]);
this.$set(this.inputForm,'sumAssured',row.sumassured);this.INPUT_FORM(this.inputForm);
let inputObj = JSON.stringify(this.inputForm);
let tmpThis = this; //这里这样子定义是因为进入CalRiderPremiumByCode方法后不能直接使用this,需要使用变量接收this值,然后再在方法里面使用变量
let indexs = index;
let row1 = row;     /** 这一段代码是与后台进行交互
      1、inputObj是方法的入参对象 ,因为在api.js中指定了入参格式为 application/json,所以应该先调用 JSON.stringify()方法格式化入参,再传给后台
2、CalRiderPremiumByCode方法需要在 service包下的 api.js文件中定义,并且在当前使用的文件中声明

     import {CalRiderPremiumByCode} from '../service/api' //此声明语句应放在<script>标签下面
  3、res是后台交互方法 CalRiderPremiumByCode(inputObj)的返回值
      4、 tmpThis.$set(...) :这是使用后台返回的数据 给表格中的当前行指定的列输入框赋值,
*/
        CalRiderPremiumByCode(inputObj).then(function(res){
if(res.code == '200' && res.msg == 'ok'){
tmpThis.$set(tmpThis.riderPlanListTableData[indexs],'premiumperyear',res.data.result.annuallypremium);
}else{
alert('后台访问出错,请刷新页面');
}
}).catch
(function(error){
console.log(error)
})

}else{
alert('保额不属于限定范围内,请重新输入!保额的最小值为:'+ row.minSumAssured+",最大值为:"+ row.maxSumAssured);
}
},

表格中嵌套select选择框的效果图:

tooltip提示框的效果图:

 

2、<el-input>框设置为不可编辑时可使用 disabled='true' 或者 readonly='true'

区别: disabled为true:不可编辑且输入框颜色变深

    readonly为true: 不可编辑,输入框颜色不变

3、页面交互参数使用 query 与 params定义

query: 相当于get方法,参数以及参数值会显示在URL上

params: 相当于post方法,参数以及参数值不会显示在URL上

params---- 请求中的使用:

使用格式:   params:{ xxxx:'123' }

注意params必须和name一起使用,且请求前面不需要加 / 

   nextstep () {
 this.$router.push({
name: 'toMain',
params: {
handPrepaidAnnualTot:this.handPrepaidAnnualTot ,
handPrepaidAnnualPrm:this.handPrepaidAnnualPrm,
paymodeOptions: this.paymodeOptions,
currencyOptions: this.currencyOptions,
}
})
},

params ---- 在请求 toMain对应的 xxxx .vue页面参数获取  :  this.$route.params.xxx

    /** 初始化调用的方法   */
selectInit() {
//1.获取从附加保障页面点击上一步 传过来的参数,如果有值则直接使用当前值填充页面数据(复显)
let tmpPrdInfoList = this.$route.params.onlProposalProductInfoList;
let tmpPrdCategoryList = this.$route.params.onlProposalCategoryInfoList;
let tmpSelectedPrdInfoList = this.$route.params.selectedPrdInforList;
let tmpPaymodeList = this.$route.params.paymodeOptions;
let tmpCurrencyList = this.$route.params.currencyOptions; },

query 请求中的使用:

注意 query必须和path一起使用,并且请求需要加 /

nextStep(){
  this.$router.push({
path: '/toMain',
query: {
handPrepaidAnnualTot:this.handPrepaidAnnualTot ,
handPrepaidAnnualPrm:this.handPrepaidAnnualPrm,
selectedPrdInforList: this.prdcodeOptions,
paymodeOptions: this.paymodeOptions,
currencyOptions: this.currencyOptions,
}
},

query-- 在请求 toMain对应的 xxxx .vue页面参数获取  :  this.$route.query.xxx

selectInit() {//1.获取从附加保障页面点击上一步 传过来的参数,如果有值则直接使用当前值填充页面数据(复显)
let tmpPrdInfoList = this.$route.query.onlProposalProductInfoList;
let tmpPrdCategoryList = this.$route.query.onlProposalCategoryInfoList;
let tmpSelectedPrdInfoList = this.$route.query.selectedPrdInforList;
let tmpPaymodeList = this.$route.query.paymodeOptions;
let tmpCurrencyList = this.$route.query.currencyOptions;
}

前端小菜鸡使用Vue+Element笔记(二)的更多相关文章

  1. 前端小菜鸡使用Vue+Element笔记(一)

    关于使用Vue+Element的项目简介~ 最近因为项目组缺前端人员,所以自己现学现做页面,先把前后台功能调通 觉得前端可真的是不容易呀哎呀~ 首先记录一下相关的Vue入门的教程: vue环境搭建示例 ...

  2. vue学习笔记(二)vue的生命周期和钩子函数

    前言 通过上一章的学习,我们已经初步的了解了vue到底是什么东西,可以干什么,而这一篇博客主要介绍vue的生命周期和它常用的钩子函数,如果有学过java的园友可能有接触到在学习servlet的时候学过 ...

  3. 小菜鸡学习---<正则表达式学习笔记2>

    正则表达式学习笔记2 一.修饰符 前面我们学习的都是用于匹配的基本的关键的一些表达式符号,现在我们来学习修饰符.修饰符不写在正则表达式里,修饰符位于表达式之外,比如/runoob/g,这个最后的g就是 ...

  4. Vue学习笔记二:v-cloak,v-text,v-html的使用

    目录 v-cloak:解决插值表达式闪烁问题 安装插件Live Server 右键以HTTP形式运行HTML v-text:以属性方式使用插值表达式 v-cloak和v-text的区别 v-html: ...

  5. VUE 学习笔记 二 生命周期

    1.除了数据属性,Vue 实例还暴露了一些有用的实例属性与方法.它们都有前缀 $,以便与用户定义的属性区分开来 var data = { a: 1 } var vm = new Vue({ el: ' ...

  6. vue使用笔记二

    es6\es2015特性http://lib.csdn.net/article/reactnative/58021?knId=1405 使用express-generator初始化你的项目目录http ...

  7. VUE学习笔记二

    package.json不可以写注释!!!!!!!!!!初始化:npm init -y 有时候使用 npm i node-sass -D 装不上,这时候,就必须使用  cnpm i node-sass ...

  8. vue学习笔记二:v-if和v-show的区别

    v-if vs v-show v-if 是“真正的”条件渲染,因为它会确保在切换过程中条件块内的事件监听器和子组件适当地被销毁和重建. v-if 也是惰性的:如果在初始渲染时条件为假,则什么也不做—— ...

  9. 循序渐进VUE+Element 前端应用开发(20)--- 使用组件封装简化界面代码

    VUE+Element 前端应用,比较不错的一点就是界面组件化,我们可以根据重用的指导方针,把界面内容拆分为各个不同的组合,每一个模块可以是一个组件,也可以是多个组件的综合体,而且这一个过程非常方便. ...

随机推荐

  1. Vim 8.0

    安装Vim 8.0yum install ncurses-devel wget https://github.com/vim/vim/archive/master.zip unzip master.z ...

  2. 基于QT的中国象棋

    基于QT的中国象棋,可实现人人对战,人机对战,联网对战,可显示棋谱,可悔棋. 还有一些小毛病,我之后会找空把这个DEMO重新修改一下上传 链接:https://pan.baidu.com/s/1-eM ...

  3. @Scope注解设置创建bean的方式和生命周期

    1.1.1            Scope注解创建bean的方式和生命周期 作用 Scope设置对象在spring容器(IOC容器)中的生命周期,也可以理解为对象在spring容器中的创建方式. 取 ...

  4. 手机计算器1+1=2---Appium自动化

    要想计算1+1=2,首先要定位到按钮1,定位方式和selenium类似

  5. mybatis-generator-core 自动生成实体和Mapper

    所谓mybatis-generator-core就是利用mybatis-generator-core.jar自动生成数据库对应的实体和映射文件.首先要下载mybatis-generator-core- ...

  6. (转)UCOSII源代码剖析

    启动工作原理 刚接触操作系统的时候觉得这个最神秘,到底里面做了什么,怎么就成了个操作系统,它到底有什么用,为什么要引进来着个东东.学了之后才知道,原来最根本的思想还是源于汇编里面的跳转和压栈,以调用一 ...

  7. Go语言学习之4 递归&闭包&数组切片&map&锁

    主要内容: 1. 内置函数.递归函数.闭包2. 数组与切片3. map数据结构4. package介绍 5. 排序相关 1. 内置函数.递归函数.闭包 1)内置函数 (1). close:主要用来关闭 ...

  8. Lab 5-1

    Analyze the malware found in the file Lab05-01.dll using only IDA Pro. The goal of this lab is to gi ...

  9. Confluence 6 如何让我的小组成员知道那些内容是重要的

    如果你的 Confluence 中已经有了很多内容,定义那些内容是重要看起是一件艰巨的任务 —— 但是下面的一些特性能够帮助你的小组确定那些内容是他们应该关心的. 我的空间(My Spaces) 添加 ...

  10. Linux命令详解-file

    file命令用来识别文件类型,也可用来辨别一些文件的编码格式.它是通过查看文件的头部信息来获取文件类型,而不是像Windows通过扩展名来确定文件类型的. 1.命令格式: file [ -bchikL ...