溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

vue前端信息詳情頁(yè)怎么實(shí)現(xiàn)

發(fā)布時(shí)間:2022-04-15 13:53:25 來(lái)源:億速云 閱讀:459 作者:iii 欄目:開發(fā)技術(shù)

這篇“vue前端信息詳情頁(yè)怎么實(shí)現(xiàn)”文章的知識(shí)點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來(lái)看看這篇“vue前端信息詳情頁(yè)怎么實(shí)現(xiàn)”文章吧。

1.HTML部分:

<template xmlns:el-form-item="http://www.w3.org/1999/xhtml">
  <el-form ref="form" :model="form" :rules="rules" label-width="100px">
    <el-page-header content="詳情頁(yè)主題" @back="goBack" />
    <el-row >
      <!--基本輸入框-->
      <el-col :span="8">
        <el-form-item label="屬性1" prop="name1">
          <el-input v-model="form.model1" placeholder="提示輸入內(nèi)容" :readonly="status"/>
        </el-form-item>
      </el-col>
      <!--基本單選框-->
      <el-col :span="8">
        <el-form-item label="屬性2" prop="name2">
          <el-select v-model="form.model2" class="whiteSelectBg" placeholder="提示單選"  :disabled="status">
            <el-option label="選項(xiàng)1" value="1" />
            <el-option label="選項(xiàng)2" value="2" />
          </el-select>
        </el-form-item>
      </el-col>
      <!--基本多選框-->
      <el-col :span="8">
        <el-form-item label="屬性3" placeholder="" prop="subjectId">
          <el-select v-model="form.model3" multiple placeholder="提示多選"  @change="getOption">
            <el-option v-for="option in options" :key="option.id" :label="option.name" :value="option.id" />
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
    <!--上傳文件-->
    <el-row>
      <el-upload :disabled="status" action="文件上傳的controller路徑" :on-success="uploadSuccess" :before-upload="beforeUpload" :show-file-list="false"
      >
        <el-col :span="20">
          <el-form-item label="文件類型名" prop="fileName">
            <el-input v-model="form.fileName" placeholder="請(qǐng)上傳實(shí)驗(yàn)指導(dǎo),可以上傳doc,docx,pdf等文檔格式" readonly  />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" icon="el-icon-upload"  :disabled="status">上傳文件</el-button>
        </el-col>
      </el-upload>
    </el-row>
    <!--數(shù)據(jù)表格-->
    <el-row>
      <el-col :span="24">
        <el-form-item>
          <el-table v-loading="listLoading" :data="form.tableList" border fit highlight-current-row  class="tb-edit" @row-click="tableChange">
            <el-table-column align="center" :label="序號(hào)" type="index" width="80"/>
            <!--普通數(shù)據(jù)格-->
            <el-table-column :label="表頭1" align="center" min-width="100px">
              <template slot-scope="{row}">
                <span>{{ row.id }}</span>
              </template>
            </el-table-column>
            <!--可編輯數(shù)據(jù)格,根據(jù)數(shù)據(jù)狀態(tài)變換輸入還是只顯示-->
            <el-table-column :label="表頭2" align="center" min-width="100px">
              <template slot-scope="{row}">
                <el-input v-if="row.seen" ref="tableInput" v-model="row.name" autofocus="autofocus" maxlength="5" @change="tableEdit(row.$index, row)" />
                <span v-else>{{ row.name }}</span>
              </template>
            </el-table-column>
            <!--操作按鈕格-->
            <el-table-column :label="'操作'" align="center" min-width="100px">
              <template slot-scope="{row}">
                <el-button size="mini" type="danger" @click="delete(row.id)">刪除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
      </el-col>
    </el-row>
    <!--基礎(chǔ)動(dòng)態(tài)表單區(qū)塊-->
    <el-card class="box-card" shadow="never" >
      <div slot="header" class="clearfix">
        <span>區(qū)塊名</span>
        <el-button type="primary" v-if="addBt"  :disabled="status" @click="addCard">新增</el-button>
      </div>
      <div >
        <el-row v-for="(card, index) in cards" :key="card.key">
          <el-col :span="8">
            <el-form-item :label="屬性1">
              <!--根據(jù)需求自己選擇放輸入框還是單選多選框-->
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="屬性2">
              <!--根據(jù)需求自己選擇放輸入框還是單選多選框-->
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-button :disabled="status" @click.prevent="deleteCard(card)">刪除</el-button>
            <el-button :disabled="status" @click="addCard">新增</el-button>
          </el-col>
        </el-row>
      </div>
    </el-card>
    <el-row>
      <el-form-item >
        <el-button type="primary" @click="submit">提交</el-button>
        <el-button @click="reset('form')">重置</el-button>
        <el-button @click="goBack">返回</el-button>
      </el-form-item>
    </el-row>   
  </el-form>
</template>

2.JS部分:

<script>
import waves from '@/directive/waves' // waves directive,點(diǎn)擊產(chǎn)生水波紋效果,在標(biāo)簽中添加 v-waves
import Pagination from '@/components/Pagination' // 分頁(yè)組件

export default {
  data() {
    return {
      id: '',
      options: [],
      guideFileIsChange: '',
      guideFile: { file: '', name: '' },
      listLoading: false,
      addBt: true,
      form: {
        model1: '',
        model2: '',
        model3: [],
        fileName: '',
        tableList: [{
          id: '',
          name: '',
          seen: false,
        },{
          id: '',
          name: '',
          seen: false,
        }]
        cards: [],     
      },
    },
    rules: {
      'model1': [{
          required: true,
          message: '請(qǐng)輸入內(nèi)容'
        }],
      'model2': [{
          required: true,
          message: '請(qǐng)選擇選項(xiàng)'
        }],
      'model3': [{
          required: true,
          message: '請(qǐng)選擇選項(xiàng)'
        }], 
      'fileName': [{
          required: true,
          message: '請(qǐng)上傳文件'
        }],
    },
  },
  // 頁(yè)面初始化
  created() {
    // 獲取上一個(gè)頁(yè)面?zhèn)鬟f過(guò)來(lái)的參數(shù),id,狀態(tài)等。。。
    this.id = this.$route.query.id
    this.action = this.$route.query.action
  },
  methods: {
    // 跳轉(zhuǎn)返回指定的頁(yè)面
    goBack() {
      this.$store.state.tagsView.visitedViews.splice(this.$store.state.tagsView.visitedViews
        .findIndex(item => item.path ===
          this.$route.path), 1)
      this.$router.push({
        path: '跳轉(zhuǎn)的頁(yè)面路徑'
      })
    },
    getOption() {
      // 獲取動(dòng)態(tài)選項(xiàng)框的數(shù)據(jù)
      const list = []
      this.options = list
    },
    // 上傳文件
    uploadSuccess(res, file) {
      this.guideFileIsChange = '1'
      this.guideFile.file = file.raw
      this.guideFile.name = file.raw.name
      this.form.fileName = file.raw.name
    },
    // 實(shí)驗(yàn)指導(dǎo)書的信息
    beforeUpload(file) {
      setTimeout(() => {
        this.$message({
          duration: 1600,
          type: 'success',
          message: '上傳文件成功!'
        })
      })
      return true
    },
    tableChange() {
      console.log('點(diǎn)擊表格行觸發(fā)的操作')
    },
    // 觸發(fā)出現(xiàn)輸入框
    tableEdit(row.$index, row) {
      for (const index in this.tableList) {
        if (row.id !== this.tableList[index].id) {
          this.tableList[index].seen = false
        } else {
          this.tableList[index].seen === false ? this.tableList[index].seen = true : this.tableList[index].seen = false
        }
      }
      if (row.seen === true) {
        this.$nextTick(() => {
          this.$refs.tableInput.focus()
        }, 100)
      }
    },
    delete(id) {
      this.$confirm('確認(rèn)刪除這一條信息?', '確認(rèn)刪除?', {
        distinguishCancelAndClose: true,
        confirmButtonText: '確定',
        cancelButtonText: '取消'
      }).then(() => {
        for (let i = 0; i < this.tableList.length; i++) {
          if (id === this.tableList[i].id) {
            this.tableList.splice(i, 1)
          }
        }
        this.$message.success('刪除成功!')
      }).catch(action => {})
    },
    addCard() {
      this.cards.push({key1: value1, key2: value2})
      this.addBt = false
    },
    deleteCard(card) {
      const index = this.cards.indexOf(card)
      if (index !== -1) {
        this.cards.splice(index, 1)
      } if (this.cards.length === 0) {
        this.addBt = true
      }
    },
    submit() {
      console.log('提交!')
    },
    reset(formName) {
      this.$refs[formName].resetFields()
    },
  },
}

3.css部分:

// 這是修改過(guò)得輸入框只讀的樣式
<style>
  .whiteSelectBg .el-input.is-disabled .el-input__inner{
    background-color: white;
    color:#606266;
  }
</style>

以上就是關(guān)于“vue前端信息詳情頁(yè)怎么實(shí)現(xiàn)”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對(duì)大家有幫助,若想了解更多相關(guān)的知識(shí)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

vue
AI