第一个需求:逆序插入到列表中

疑难百度结果:
this.$nextTick()在页面交互,尤其是从后台获取数据后重新生成dom对象之后的操作有很大的优势,这里只是简单的例子,实际应用中更为好用~

示例: client/detail
html

<el-row>
      <el-card class="box-card" style="margin-bottom: 20px">
        <div slot="header" class="clearfix" style="height: 10px;margin-bottom:10px">
          <span style="font-weight: bold;float: left;margin-top: 4px;">账户信息</span>
          <el-button style="float: right;font-size: 20px;margin-top:-10px;cursor: pointer" type="text"
                     @click="showClientAccountDialog">
            <i class="el-icon-plus"/>
          </el-button>
        </div>
        <div class="item">
          <el-table :data="accounts" style="width: 100%" border>
            <el-table-column prop="name" label="名称"/>
            <el-table-column prop="type" label="类型" width="200">
              <template slot-scope="scope">
                <span v-text="clientAccountType[scope.row.type]"></span>
              </template>
            </el-table-column>
            <el-table-column prop="state" label="状态" width="200">
              <template slot-scope="scope">
                <span v-text="clientAccountState[scope.row.state]"></span>
              </template>
            </el-table-column>
            <el-table-column prop="start" label="开始日期" :formatter="formatDate" width="300"/>
            <el-table-column prop="end" label="结束日期" :formatter="formatDate" width="300"/>
            <el-table-column prop="action" label="操作" width="100">
              <template slot-scope="scope">
                <el-button @click="editAccount(scope.row.id)" size="small" type="text">编辑</el-button>
                <el-button @click="deleteClientAccount(scope.row.id)" size="small" type="text">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-card>
    </el-row>

js:

 showClientAccountDialog: function () {
        this.clientAccountTitle = "添加客户账户"
        this.clientAccountId = ''
        this.clientInvoiceInfo = {}
        this.$nextTick(() => {
          this.$refs['clientInvoiceInfo'].clearValidate()
        })
        this.loading = false
        this.dialogClientInvoiceVisible = true
      },

展示出添加客户账号的初始化信息。
this.$nextTick,让下面的语句在dom重新生成后再操作。
再重置一下布尔值。

疑问?这个点击方法和弹出框层无关吧?仅仅是初始化吧!

我的需求:点击➕:填入信息,信息填好后点击确认按钮,新的信息项加入到表格最上面一行。作为逆序存储。

弹层在最后写入:
第385行:

    <el-dialog :title="clientAccountTitle" :close-on-click-modal="false" :visible.sync="dialogClientInvoiceVisible"
               :width="'32%'">
      <el-form :model="clientInvoiceInfo" ref="clientInvoiceInfo">
        <el-form-item label="账户名称" :label-width="formLabelWidth" prop="name"
                      :rules="[{required:true,message:'请输入账户名称',trigger:'change'}]" style="width: 93%">
          <el-input v-model="clientInvoiceInfo.name" size="small" autocomplete="off"/>
        </el-form-item>
        <el-form-item label="账户类型" :label-width="formLabelWidth" prop="type"
                      :rules="[{required:true,message:'请选择账户类型',trigger:'change'}]" style="width: 90%;">
          <el-radio v-model="clientInvoiceInfo.type" style="margin-top:11px" label="conventional">常规</el-radio>
          <el-radio v-model="clientInvoiceInfo.type" style="margin-top:11px" label="temporary">临时</el-radio>
        </el-form-item>
        <el-form-item label="账户状态" :label-width="formLabelWidth" prop="state"
                      :rules="[{required:true,message:'请选择账户状态',trigger:'change'}]" style="width: 90%;">
          <el-radio v-model="clientInvoiceInfo.state" style="margin-top:11px" label="enable">有效</el-radio>
          <el-radio v-model="clientInvoiceInfo.state" style="margin-top:11px" label="disable">无效</el-radio>
          <el-radio v-model="clientInvoiceInfo.state" style="margin-top:11px" label="hedged">已对冲</el-radio>
        </el-form-item>
        <el-form-item label="开始日期" :label-width="formLabelWidth" prop="start"
                      :rules="[{required:true,message:'请选择开始日期',trigger:'change'}]" style="width: 93%">
          <el-date-picker v-model="clientInvoiceInfo.start" size="small" type="date" placeholder="选择开始日期"
                          format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width: 100%"
                          :picker-options="pickerOptionsStart"/>
        </el-form-item>

        <el-form-item label="结束日期" :label-width="formLabelWidth" prop="end"
                      :rules="[{required:true,message:'请选择结束日期',trigger:'change'}]" style="width: 93%">
          <el-date-picker v-model="clientInvoiceInfo.end" :width="'100%'" size="small" type="date" placeholder="选择结束日期"
                          format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width: 100%"
                          :picker-options="pickerOptionsEnd"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="width: 93%">
        <el-button size="small"
                   @click="resetForm('clientInvoiceInfo');dialogClientInvoiceVisible = false;clientInvoiceInfo={}">取 消
        </el-button>
        <el-button size="small" type="primary" :loading="loading" @click="saveClientAccountInfo('clientInvoiceInfo')">确
          定
        </el-button>
      </div>
    </el-dialog>

确认点击事件的方法:
714:

  saveClientAccountInfo: function (formName) {
        if (this.clientAccountId == '') {
          this.addClientAccountInfo(formName)
        } else {
          this.updateClientAccountInfo(formName)
        }
      },

逻辑:如果这个id不存在,调用添加方法,不然就调用更新方法。
createAccount()
validate()
this.$refs[formName]
getAccountInfos() 初始化函数中初始化过了。(initClientDetail)
dialogClientInvoiceVisible

在data中声明过的:
loading: false,
clientInvoiceInfo: {},
dialogClientInvoiceVisible: false,

主体部分:用v-bind接受了一个:name type 在data部分的

client: {
          area: '',
          name: '',
          shortName: '',
          type: '',
          scoringCycle: [],
          paymentType: '',
        },
```表格用v-bind接受了一个accouts
第一列用prop接受了一个name
第二列用prop接受了一个type,在其中包含了一个模版语法,   使用v-text接受了"clientAccountType[scope.row.type]"
第三列用prop接受了一个state,在其中包含了一个模版语法,"clientAccountState[scope.row.state]"
第四列用prop接受了一个start  表示开始时间
第五列用prop接受了一个end 表示结束时间
第六列用prop接受了一个action,在其中包含了一个模版语法,在其中定义了两个button ,绑定了对应的点击函数:
@click="editAccount(scope.row.id)" 
@click="deleteClientAccount(scope.row.id)"

editAccount: function (accountId) {
this.clientAccountTitle = “编辑客户账户”
this.clientInvoiceInfo = {}
getClientAccountInfo(this.clientId, accountId).then(res => {
this.clientAccountId = accountId
this.clientInvoiceInfo = res.data
this.KaTeX parse error: Expected '}', got 'EOF' at end of input: … this.refs[‘clientInvoiceInfo’].clearValidate()
})
this.loading = false
this.dialogClientInvoiceVisible = true
})
},




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 存放数组的数据可以使用 reverse() 函数或切片语法,例如: ``` arr = [1, 2, 3, 4, 5] arr.reverse() print(arr) # 或者 arr = [1, 2, 3, 4, 5] arr = arr[::-1] print(arr) ``` 输出指定元素,可以直接使用下标访问,例如: ``` arr = [1, 2, 3, 4, 5] print(arr[2]) ``` ### 回答2: 存放数组的数据,就是将数组的元素从最后一个元素开始依次插入一个新数组,然后输出新数组。这个过程可以通过以下伪代码来实现: 1. 定义一个新数组newArr,用于存放后的数据; 2. 遍历原数组arr,从最后一个元素开始依次插入newArr; 3. 输出newArr指定元素。 具体实现代码如下(使用Python语言): ```python # 定义原数组 arr = [1, 2, 3, 4, 5, 6, 7, 8] # 定义一个新数组,用于存放后的数据 newArr = [] # 从最后一个元素开始遍历原数组,依次插入新数组 for i in range(len(arr)-1, -1, -1): newArr.append(arr[i]) # 输出新数组指定元素(例如第3个元素) print(newArr[2]) # 输出:6 ``` 在这段代码,我们使用了Python的for循环语句,通过指定range函数的参数,从len(arr)-1即数组最后一个元素开始,到-1(不包括-1),以步长-1()的方式遍历原数组arr。然后将每个元素依次插入新数组newArr。最后,通过指定newArr的下标来输出新数组所需的元素。 存放数组的数据,可以方便地实现数组元素的倒查找和修改等操作,帮助我们更方便地处理数据。 ### 回答3: 首先,我们需要理解什么是存放数组的数据。存放就是把原来排在前面的元素放到后面,原来排在后面的元素放到前面,将数组翻转过来。 在编写代码的时候,可以使用一个for循环,从数组的末尾开始,依次将元素存放到一个新的数组。代码如下: ``` int[] array = {1, 2, 3, 4, 5}; int[] newArray = new int[array.length]; for (int i = array.length - 1; i >= 0; i--) { newArray[array.length - i - 1] = array[i]; } ``` 在这段代码,我们定义了一个原数组array和一个新数组newArray,使用for循环将原数组的元素存放到新数组。为了实现,我们从原数组的末位开始循环,并将元素存放到新数组的开头。 接下来,我们需要输出指定元素。输出指定元素可以通过访问数组的特定下标来实现。例如,输出新数组的第二个元素,可以使用以下代码: ``` System.out.println(newArray[1]); ``` 在这段代码,我们使用数组下标1来访问新数组的第二个元素,并通过System.out.println()函数将其输出到控制台。 在实际开发存放数组和输出指定元素都是比较常见的需求,因此我们需要熟练掌握这些操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值