国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vue3 element-plus el-form的二次封裝

這篇具有很好參考價(jià)值的文章主要介紹了vue3 element-plus el-form的二次封裝。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

form表單的二次封裝

vue3 element-plus el-form的二次封裝文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-539787.html

屬性說(shuō)明

屬性名 類型 默認(rèn)值 說(shuō)明
data Array [] 頁(yè)面展示數(shù)據(jù)內(nèi)容
onChange Function false 表單事件
bindProps Object {} 表單屬性
formRef Object {} 表單ref
ruleForm Object {} 數(shù)據(jù)

使用示例

	//形式一
	 <formCustom
        :data="searchHeaders"
        :bindProps="{ inline: true }"
        :ruleForm="searchRuleForm"
      ></formCustom>

	//形式二
	 <formCustom
      :data="formHeaders"
      :bindProps="{ 'label-width': '124px', 'scroll-to-error': true }"
      v-model:formRef="formRef"
      :ruleForm="ruleForm"
    ></formCustom>
// setup 形式下
import { ref,active } from 'vue'
import formCustom from "@/components/custom-form-v3/searchForm"
const formProps = {
  style: {
    marginBottom: "0",
    marginRight: "16px",
  },
};
const searchRuleForm = reactive({}); //搜索的數(shù)據(jù)

const ruleForm = reactive({}); //表單的數(shù)據(jù)
const formRef = ref()
const searchHeaders = reactive([
	{
		formProps,
		render: () => {
		return (
			<div class="flex-d-r-center">
			<div
				class="db-primary-button flex-d-r-center"
				onClick={() => addTools()}
			>
				<span class="iconfont icon-style icon-left">
				&#xe62d;
				</span>
				新增
			</div>
			</div>
		);
		},
	},
	{
		formProps: {
			style: {
				flex: 1,
				"margin-bottom": 0,
			},
		},
  	},
	{
		Component: "ElSelect",
		formProps,
		prop: "status",
		componentProps: {
			clearable:true,
			placeholder: "狀態(tài)",
			style: {
				width: "101px",
			},
		},
		componentSlots: {
			default: () => {
				const data = [
				{
					label: "進(jìn)行中",
					value: 1,
				},
				{
					label: "已結(jié)束",
					value: 2,
				},
				{
					label: "未開(kāi)始",
					value: 3,
				},
				];
				return data.map((item) => {
					return (
						<el-option
						value={item.value}
						label={item.label}
						key={item.value}
						></el-option>
					);
				});
			},
		},
  	},
	{
		Component: "ElInput",
		formProps,
		prop: "title",
		componentProps: {
			placeholder: "請(qǐng)輸入名稱",
			style: {
				width: "205px",
			},
		},
  	},
	{
		formProps: {
			style: {
				marginBottom: "0",
				marginRight: "0",
			},
		},
		render: () => {
			return (
				<div
				class="db-primary-button flex-d-r-center"
				onClick={() => searchRes()}
				>
				<span class="iconfont icon-style icon-left">
					&#xe624;
				</span>
				查詢
				</div>
			);
		},
  	},
])

const formHeaders = reactive([
	{
		label:"時(shí)間",
		prop: "times",
		span: 24,
		defaultValue: "",
		Component: "ElDatePicker",
		on: {
			change: () => {},
		},
		componentProps: {
			type: "datetimerange",
			"value-format": "YYYY-MM-DD HH:mm:ss",
			format: "YYYY-MM-DD HH:mm:ss",
			rangeSeparator: "-",
			startPlaceholder: "開(kāi)始時(shí)間",
			endPlaceholder: "結(jié)束時(shí)間",
			disabled: computed(() => isDisabled(1)),
			style:{
				width: '340px'
			}
		},
		formProps: {
			rules: {
				required: true,
				trigger: "blur",
				validator: (rule, value, callback) => {
				if (value === "") {
					callback(new Error("請(qǐng)輸入搶購(gòu)時(shí)間"));
				}
				callback();
				},
			},
		},
  	},
	{
		label: "名稱",
		prop: "name",
		Component: "ElInput",
		defaultValue: "",
		componentProps: {
			placeholder: "名稱需2-30個(gè)字符(漢字占兩個(gè)字符)",
			style: {
				width: "540px",
			},
		},
		formProps: {
			rules: {
				required: true,
				trigger: "blur",
				// message: "請(qǐng)輸入講師名稱",
				validator: (rule, value, callback) => {
				if(value === '') {
					callback(new Error('請(qǐng)輸入講師名稱'))
				}
				const len = strLength(value)
				if(len < 2 || len > 30) {
					callback(new Error('講師名稱需2-30個(gè)字符'))
				}
				callback()
				}
			},
		},
  	},
	{
		label: "狀態(tài)",
		prop: "status",
		span: 24,
		Component: switchCons,
		defaultValue: 0,
		componentProps: {
			style: {
				width: "540px",
			},
		},
		formProps: {
			rules: {
				required: true,
				trigger: "blur",
			},
		},
  	},
])

const isDisabled = (type) => {
  const obj = {
    1: [1],
    2: [1,3]
  }
  return obj[type].includes(ruleForm.status)
}

const saveForm = () => {
  formRef.value.validate(async (valid) => { // 提交數(shù)據(jù)時(shí)驗(yàn)證表單
    if(valid) {
      
    }
  })
};

const addTools = () => {
  router.push({
    path: "/add"
  });
};
const searchRes = () => {
  useTableRef.value.getRequestRes("firstPage"); //刷新表格
};


//也可以注冊(cè)到全局 頁(yè)面中直接使用不需要import
// main.ts文件
import App from '@/App.vue'
import formCustom from "@/components/custom-form-v3/searchForm"
const app = createApp(App)
app.component('formCustom', formCustom)

到了這里,關(guān)于vue3 element-plus el-form的二次封裝的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • element plus el-form雙列布局及拓展任意布局

    element plus el-form雙列布局及拓展任意布局

    一般表單我們直接默認(rèn)布局,也就是單列布局,突然有個(gè)人員信息表單,需要雙列布局的需求,簡(jiǎn)單實(shí)現(xiàn)并拓展下 直接無(wú)腦div+flex布局實(shí)現(xiàn) 這樣的無(wú)腦實(shí)現(xiàn)實(shí)在是對(duì)不起付出的時(shí)間,不嫩復(fù)用是最大問(wèn)題 封裝el-form,增加slot // Form.vue // index.vue 依然不夠通用,因?yàn)椴季质枪潭?/p>

    2024年01月25日
    瀏覽(23)
  • Vue3 element-plus el-select 無(wú)法選中,又不報(bào)錯(cuò)

    Vue3 element-plus el-select 無(wú)法選中,又不報(bào)錯(cuò)

    html 結(jié)構(gòu) js 代碼 點(diǎn)擊下拉選項(xiàng),輸入框無(wú)法選中 原因:ref=“conditionForm” 和 :model=“conditionForm” 沖突了, 4-1. 再Vue2里面 :model=“conditionForm” 綁定的是 conditionForm 變量, ref=“conditionForm” 綁定的是conditionForm字符串 v-model=“conditionForm.personnel” 綁定的 conditionForm 變量下屬性

    2023年04月27日
    瀏覽(26)
  • vue3+element-plus+el-image實(shí)現(xiàn)點(diǎn)擊按鈕預(yù)覽大圖

    需求:點(diǎn)擊某個(gè)按鈕實(shí)現(xiàn)el-image中預(yù)覽大圖的效果 官方文檔:以下是官方的寫法,并不能達(dá)到我們的要求,官方實(shí)現(xiàn)的功能是點(diǎn)擊圖片達(dá)到預(yù)覽大圖的效果。如果你的按鈕就是圖片,也可以達(dá)到目前的功能 el-image-viewer組件是element官方的組件,只是文檔中沒(méi)有寫出來(lái),這個(gè)組

    2024年02月12日
    瀏覽(33)
  • vue3.0 element-plus 不同版本 el-popover 循環(huán)優(yōu)化

    vue3.0 element-plus 不同版本 el-popover 循環(huán)優(yōu)化

    表格內(nèi)循環(huán)el-popover? 渲染以后的頁(yè)面,數(shù)據(jù)量很大的時(shí)候頁(yè)面會(huì)卡,生成的代碼: 解決思路: 將el-popover提出來(lái),不參與循環(huán),讓el-popover只渲染一次 ? 1、以1.1.0-beta.24版為例(低版本) 紅色下劃線部分是關(guān)鍵點(diǎn) ? ? v-popover的值與el-popover的ref值要一致 2、以2.3.9版為例(當(dāng)前

    2024年02月12日
    瀏覽(29)
  • vue3使用element-plus 樹組件(el-tree)數(shù)據(jù)回顯

    html搭建結(jié)構(gòu) js 非常好用,拿過(guò)來(lái)修改一下check事件,ref獲取就直接可以使用了?

    2024年04月09日
    瀏覽(99)
  • 【踩坑筆記】vue3 element-plus el-input 無(wú)法輸入問(wèn)題

    原因是 el-form 的 v-model=\\\"loginForm\\\" ref=\\\"loginForm\\\" 在vue3中值不能相同 把ref去掉或者改名即可 這是js的代碼( 對(duì)象記得用reactive,不然也會(huì)無(wú)法輸入 ) 這個(gè)是可以輸入的 這是無(wú)法輸入的 就改了個(gè)ref

    2024年02月11日
    瀏覽(31)
  • 【Element Ui】 vue3中修改el-form的rules后不觸發(fā)自動(dòng)校驗(yàn),再次修改rules時(shí)清除驗(yàn)證信息

    【Element Ui】 vue3中修改el-form的rules后不觸發(fā)自動(dòng)校驗(yàn),再次修改rules時(shí)清除驗(yàn)證信息

    項(xiàng)目要求:類型為“業(yè)務(wù)備貨”的時(shí)候,“客戶”為必填項(xiàng) 效果如下: 代碼如下: 重點(diǎn):

    2024年04月12日
    瀏覽(24)
  • Vue - Element el-form 表單對(duì)象多層嵌套校驗(yàn)

    針對(duì)el-form的數(shù)據(jù)源是對(duì)象嵌套對(duì)象,在進(jìn)行數(shù)據(jù)綁定和校驗(yàn)時(shí)和單層的對(duì)象有一點(diǎn)區(qū)別, 具體是下面兩部分: 數(shù)據(jù)源: 1、 給 el-form-item 的 prop 設(shè)為: prop=\\\"health.height\\\" 。 v-model 設(shè)為: v-model=\\\"fromData.health.height\\\" 2、校驗(yàn)規(guī)則 rules 對(duì)象對(duì)應(yīng)的key設(shè)置為數(shù)據(jù)源內(nèi)部的值: \\\'health.heig

    2024年02月14日
    瀏覽(34)
  • el-form 動(dòng)態(tài)表單增減項(xiàng) (vue+element ui)

    el-form 動(dòng)態(tài)表單增減項(xiàng) (vue+element ui)

    1、點(diǎn)擊”+“,彈出彈窗,新增一項(xiàng),點(diǎn)擊”-“,刪除當(dāng)前項(xiàng) 代碼展示: html代碼: 注意: el-form-item(表單項(xiàng))循環(huán),綁定的數(shù)組寫在form當(dāng)中 表單: 新增參數(shù)彈框: data: methods: 1、點(diǎn)擊新增,彈出新增彈窗,添加表單項(xiàng) 2、點(diǎn)擊”-“,刪除當(dāng)前表單項(xiàng)

    2024年02月02日
    瀏覽(27)
  • Vue+Element(el-upload+el-form的使用)+springboot

    Vue+Element(el-upload+el-form的使用)+springboot

    目錄 1、編寫模板 ?2、發(fā)請(qǐng)求調(diào)接口 ?3、后端返回?cái)?shù)據(jù) 1.編寫實(shí)體類 2.Controller類? 3、interface接口(Service層接口) ?4.Service(接口實(shí)現(xiàn)) 5、interface接口(Mapper層接口) 6、xml 7、goods.sql 8、goods_img 4、upload相關(guān)參數(shù)? ?說(shuō)明(該案例是一個(gè)el-form和el-upload結(jié)合的,邏輯是:需要

    2024年01月25日
    瀏覽(45)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包