一、vue中使用el-table的type=index有時不顯示序號
Table 表格
用于展示多條結(jié)構(gòu)類似的數(shù)據(jù),可對數(shù)據(jù)進(jìn)行排序、篩選、對比或其他自定義操作。
當(dāng)el-table元素中注入data對象數(shù)組后,在el-table-column中用prop屬性來對應(yīng)對象中的鍵名即可填入數(shù)據(jù),用label屬性來定義表格的列名??梢允褂脀idth屬性來定義列寬。
顯示索引
如果需要顯示索引,可以增加一列el-table-column,設(shè)置type屬性為index即可顯示從 1 開始的索引號。
<el-table-column
type="index"
width="50">
</el-table-column>
自定義索引
通過給 type=index 的列傳入 index 屬性,可以自定義索引。該屬性傳入數(shù)字時,將作為索引的起始值。也可以傳入一個方法,它提供當(dāng)前行的行號(從 0 開始)作為參數(shù),返回值將作為索引展示。
<el-table-column
type="index"
:index="indexMethod">
</el-table-column>
methods: {
indexMethod(index) {
return index * 2;
}
}
報錯信息
el-table中通過type=index來顯示序號。有時候序號不能正常顯示。
解決方案
使用template來換一種寫法
<el-table-column label="序號" width="50" align="center">
<template slot-scope="scope">{{scope.$index+1}}</template>
</el-table-column>
二、vue中Missing required prop: “value” 報錯
報錯原因
- 表單中沒有進(jìn)行雙向數(shù)據(jù)綁定(v-model)
<el-form-item label="活動名稱">
<el-input></el-input>
</el-form-item>
- el-option沒有進(jìn)行value賦值
<el-select v-model="value" placeholder="請選擇">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label">
</el-option>
</el-select>
解決方案
- 表單中每一項都要使用v-model綁定
<el-form-item label="活動名稱">
<el-input v-model="form.name"></el-input>
</el-form-item>
- el-option進(jìn)行value賦值
<el-select v-model="value" placeholder="請選擇">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
若el-select進(jìn)行了雙向數(shù)據(jù)綁定,且每一項el-option都進(jìn)行了value賦值,然而還報了這個錯,這時需要檢查下每一項綁定value的變量是否都在數(shù)組中存在。
三、el-table的索引值index在翻頁的時候可以連續(xù)顯示
方法一
通過給 type=index 的列傳入 index 屬性,可以自定義索引。該屬性傳入數(shù)字時,將作為索引的起始值。也可以傳入一個方法,它提供當(dāng)前行的行號(從 0 開始)作為參數(shù),返回值將作為索引展示。
<template>
<el-table
:data="tableData"
style="width: 100%">
<el-table-column
type="index"
:index="indexMethod">
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return { }
},
methods: {
indexMethod(index) {
// index 當(dāng)前序號,pageSize 每頁顯示的條數(shù),currentPage 當(dāng)前頁碼
return index + this.pageSize * ( this.currentPage - 1 ) + 1
}
}
};
</script>
方法二
通過 Scoped slot 可以獲取到 row, column, $index 和 store(table 內(nèi)部的狀態(tài)管理)的數(shù)據(jù)。
<template>
<el-table
:data="tableData"
style="width: 100%">
<el-table-column
type="index">
<template slot-scope="scope">
<span>{{ scope.$index + pageSize * ( currentPage - 1 ) + 1 }}</span>
</template>
</el-table-column>
</el-table>
</template>
四、vue3中Element Plus全局組件配置中文的兩種方案
Element+是一款用于制作頁面樣式,設(shè)計頁面結(jié)構(gòu)的框架。相比于其他的幾個框架,這個框架設(shè)計的更為人性化,對企業(yè)級框架VUE的集成也很高。
Element Plus 組件 默認(rèn) 使用英語,如果你希望使用其他語言,你可以參考下面的兩種方案。文章來源:http://www.zghlxwxcb.cn/news/detail-795508.html
1.在 App.vue 的文件中修改
<template>
<el-config-provider :locale="locale">
<router-view></router-view>
</el-config-provider>
</template>
<script setup>
// // 引入配置組件
import { ElConfigProvider } from 'element-plus'
// 引入中文包
import zhCn from 'element-plus/lib/locale/lang/zh-cn';
const { locale } = reactive({
locale: zhCn,
});
</script>
2.在main.js的文件中修改
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
app.use(ElementPlus, {
locale: zhCn,
})
國際化
Element Plus 還提供了一個 Vue 組件 ConfigProvider 用于全局配置國際化的設(shè)置。文章來源地址http://www.zghlxwxcb.cn/news/detail-795508.html
<template>
<el-config-provider :locale="locale">
<app />
</el-config-provider>
</template>
<script>
import { defineComponent } from 'vue'
import { ElConfigProvider } from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
export default defineComponent({
components: {
ElConfigProvider,
},
setup() {
return {
locale: zhCn,
}
},
})
</script>
到了這里,關(guān)于Vue開發(fā)中使用Element UI過程中遇到的問題及解決方案Missing required prop: “value”,Element Plus全局組件配置中文的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!