最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解vue如何給特殊字段設(shè)置插槽

 更新時間:2023年09月13日 10:50:15   作者:明思齊  
這篇文章主要為大家詳細介紹了vue如何實現(xiàn)給特殊字段設(shè)置插槽,文中的示例代碼講解詳細,具有一定的借鑒價值,有需要的小伙伴可以學(xué)習(xí)一下

大綱:

<template>
  <div>
    <div>
      <span>卡號</span>
      <el-input type="text" v-model="cardNo" clearable placeholder="請輸入卡號" />
      <el-button type="primary" plain icon="el-icon-search" @click="search">搜索</el-button>
    </div>
    <!-- 表格 -->
    <el-table class="fontTextStyle" border :header-cell-style="{background:'#f0f9eb'}" :data="data" style="width: 100%">
      <el-table-column align="center" prop="staffName" label="姓名"></el-table-column>
      <el-table-column align="center" prop="deptName" label="部門"></el-table-column>
      <el-table-column align="center" prop="cardNo" label="卡號" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column align="center" prop="termNo" label="設(shè)備號"></el-table-column>
      <el-table-column align="center" prop="datails" label="菜品">
        <template slot-scope="scope">
          <el-popover placement="top-start" trigger="click">
            <el-tag size="small" style="margin-right: 10px;" v-for="item in scope.row.details" :key="item.pid">
              {{ item.name }} X {{ item.qty }}份
            </el-tag>
            <el-button type="text" slot="reference"> {{scope.row.details.length}}個菜品</el-button>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="amt" label="消費金額"></el-table-column>
      <el-table-column align="center" prop="balance" label="余額"></el-table-column>
      <el-table-column align="center" prop="payTime" label="支付時間" :show-overflow-tooltip="true"></el-table-column>
    </el-table>
  </div>
</template>
<script>
  import API from '@/components/common/Api'
  export default {
    data() {
      return {
        //查詢參數(shù)
        pn: 1,
        ps: 10,
        count: 0,
        data: [],
        form: {},
        cardNo: '',//搜索鍵值
        datails: '',
      }
    },
    mounted() {
      this.getList()
    },
    methods: {
      search() {
        this.getList();
      },
      //獲取智盤支付記錄列表
      getList() {
        let params = {
          cardNo: this.cardNo,
        }
        API.getPosPayLog(params).then(result => {
          if (result.data && result.data.code == 0) {
            this.data = result.data.data.list || [];
            //循環(huán)遍歷菜品
            this.data.forEach(item => {
              item.details = JSON.parse(item.details)
            })
            this.count = result.data.data.total
          }
        });
      },
    },
  }
</script>
<style></style>

代碼詳解:

代碼中使用了 Element UI 的組件,包括 el-input (輸入框)、 el-button (按鈕)、 el-table (表格)、 el-table-column (表格列)和 el-popover (氣泡彈出框)等等。

第一步: 在頁面初始化時,通過 mounted 鉤子函數(shù)調(diào)用 getList 方法獲取支付記錄列表,并將結(jié)果保存在 data 數(shù)組中。當點擊搜索按鈕時,會觸發(fā) search 方法,該方法再次調(diào)用 getList 方法進行搜索。

第二步: getList 方法發(fā)送請求到后端接口,傳遞卡號作為參數(shù)。當接口返回數(shù)據(jù)后,將數(shù)據(jù)賦值給 data 數(shù)組,并使用 JSON.parse 將菜品詳情從字符串解析為對象數(shù)組。

第三步:通過循環(huán)遍歷 data 數(shù)組中的每一項,將菜品詳情 item.details 解析為對象數(shù)組,以便在表格中展示。

注意:具體的接口返回的數(shù)據(jù)類型可能會有所不同,可以根據(jù)實際需求進行調(diào)整。

類型:字符串json

<template>
  <div>
    <avue-crud ref="crud" v-model="form" :data="data" :option="option">
      <!-- 消費商品 -->
      <template slot-scope="scope" slot="payOrder">
        <el-popover trigger="click" title="" v-if="scope.row.payOrder.length">
          <div>
            <el-tag size="small" v-for="(item,index) in viewList" :key="index">
              {{ item.name }}X{{ item.num }}份
            </el-tag>
          </div>
          <el-button slot="reference" type="text" size="small" @click="getmenu(scope.row.payOrder)">
            {{ scope.row.payOrder.length }}個菜品
          </el-button>
        </el-popover>
        <div v-else>無</div>
      </template>
    </avue-crud>
  </div>
</template>
<script>
  import API from '@/components/common/Api';
  export default {
    data() {
      return {
        /* data:[]后端獲取到的數(shù)據(jù)列表。option表格配置項.form 表單*/
        data: [],
        form: {},
        query: {}, //搜索鍵值
        viewList: [],
        option: {
          size: 'mini', //表格大小 medium/small/mini
          border: true,
          align: 'center',
          viewBtn: false, //查看詳情按鈕
          editBtn: false, //編輯修改按鈕
          delBtn: false, //刪除按鈕
          addBtn: false,
          menu: false,
          column: [{
              label: '消費商品', //表頭
              prop: 'payOrder', //鍵值
              slot: true,
            }]
        },
      }
    },
    mounted() {
      this.onLoad()
    },
    methods: {
      // 根據(jù)接口獲取data數(shù)據(jù)
      onLoad() {
        let params = {
          data: this.query,
        }
        API.yktPosPayLogAll(params).then(res => {
          if (res.data.code == 0) {
            this.data = res.data.data.list;
            //循環(huán)遍歷商品
            this.data.forEach(item => {
              item.payOrder = JSON.parse(item.payOrder);
            })
          }
        })
      },
      getmenu(arr) {
        this.viewList = arr;
      },
    }
  }
</script>
<style></style>
<template>
    <avue-crud :option="option" :data="data" v-model="form" ref="crud">
      <template slot-scope="scope" slot="posFoodReserveDetail">
        <el-popover trigger="click" title="菜單">
          <div>
            <el-tag size="small" v-for="item in viewList" :key="item.foodId">
              {{ item.foodName }}X{{ item.reserveNum }}份
            </el-tag>
          </div>
          <el-button slot="reference" type="text" size="small" @click="getmenu(scope.row.posFoodReserveDetail)">
            {{ scope.row.posFoodReserveDetail.length }}個菜品
          </el-button>
        </el-popover>
      </template>
    </avue-crud>
</template>
<script>
  import API from '@/components/common/newApi';
  export default {
    data() {
      return {
        data: [],
        form: {},
        query: {},
        option: {
          border: true,
          column: [{
              label: '預(yù)定內(nèi)容',
              prop: 'posFoodReserveDetail',
              slot: true,
              overHidden: true,
            }]
        },
        viewList: []
      };
    },
    mounted() {
      this.onLoad();
    },
    methods: {
      // 加載表格數(shù)據(jù)
      onLoad() {
        let param = {
          data: this.query
        };
        API.selectMyReserve(param).then(res => {
          if (res.data.code === 0) {
            this.data = res.data.data.list;
          }
        });
      },
      getmenu(arr) {
        this.viewList = arr;
      },
    }
  };
</script>
<style></style>

代碼詳解:

在這個插槽中,我使用了 el-popover 組件來顯示菜單信息,并通過點擊按鈕觸發(fā)了 getmenu 方法。根據(jù)我這邊的業(yè)務(wù)需求,我將在點擊按鈕時調(diào)用 getmenu 方法,并將傳入的 scope.row.posFoodReserveDetail 賦值給 viewList。

類型:數(shù)組

以上就是詳解vue如何給特殊字段設(shè)置插槽的詳細內(nèi)容,更多關(guān)于vue插槽的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • vue中添加mp3音頻文件的方法

    vue中添加mp3音頻文件的方法

    本篇文章主要介紹了vue中添加mp3音頻文件的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • vue實現(xiàn)打包添加二級目錄

    vue實現(xiàn)打包添加二級目錄

    這篇文章主要介紹了vue實現(xiàn)打包添加二級目錄方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • 深入探討Vue計算屬性與監(jiān)聽器的區(qū)別和用途

    深入探討Vue計算屬性與監(jiān)聽器的區(qū)別和用途

    在Vue的開發(fā)中,計算屬性(Computed Properties)和監(jiān)聽器(Watchers)是兩種非常重要的概念,它們都用于響應(yīng)式地處理數(shù)據(jù)變化,本文將帶你深入了解計算屬性和監(jiān)聽器的區(qū)別,以及在何時使用它們,感興趣的朋友可以參考下
    2023-09-09
  • 從vue源碼看props的用法

    從vue源碼看props的用法

    平時寫vue的時候知道 props 有很多種用法,今天我們來看看vue內(nèi)部是怎么處理 props 中那么多的用法的。非常具有實用價值,需要的朋友可以參考下
    2019-01-01
  • vue使用v-model進行跨組件綁定的基本實現(xiàn)方法

    vue使用v-model進行跨組件綁定的基本實現(xiàn)方法

    這篇文章主要給大家介紹了關(guān)于vue使用v-model進行跨組件綁定的基本實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • Nuxt.js nuxt-link與router-link的區(qū)別說明

    Nuxt.js nuxt-link與router-link的區(qū)別說明

    這篇文章主要介紹了Nuxt.js nuxt-link與router-link的區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • Vue.js標簽頁組件使用方法詳解

    Vue.js標簽頁組件使用方法詳解

    這篇文章主要為大家詳細介紹了Vue.js標簽頁組件的使用方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一
    2019-10-10
  • Vue.js路由組件vue-router使用方法詳解

    Vue.js路由組件vue-router使用方法詳解

    這篇文章主要為大家詳細介紹了Vue.js路由組件vue-router使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Vue路由配置項和參數(shù)使用及說明

    Vue路由配置項和參數(shù)使用及說明

    文章介紹了Vue路由中query和params參數(shù)的傳遞與接收、命名路由簡化跳轉(zhuǎn)、props配置參數(shù)、router-link的replace屬性、編程式導(dǎo)航、路由組件緩存及activated和deactivated兩個生命周期鉤子的用法
    2025-10-10
  • 關(guān)于vue-lunar-full-calendar的使用說明

    關(guān)于vue-lunar-full-calendar的使用說明

    這篇文章主要介紹了關(guān)于vue-lunar-full-calendar的使用說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-07-07

最新評論

利辛县| 寻甸| 比如县| 平陆县| 朝阳区| 东平县| 吉木萨尔县| 安义县| 龙游县| 德阳市| 翼城县| 邢台市| 新疆| 察哈| 漳浦县| 库伦旗| 赤峰市| 宣汉县| 贡山| 承德县| 阜平县| 双柏县| 山阳县| 荥经县| 乐清市| 清涧县| 休宁县| 饶阳县| 宾川县| 尤溪县| 武安市| 潜江市| 永川市| 东阿县| 休宁县| 孟连| 天等县| 汕尾市| 韩城市| 萍乡市| 荔波县|