Ts声明ElementUI控件

初用Ts,有时候想获取三方控件不太会声明类型,记录一下使用InstanceType导入类型
例如声明一个el-select

<el-form-item label="类型:" prop="year" :loading="state.loading">
       <el-select v-model="props.ruleForm.version" class="m-2" placeholder="请选择类型" @change="change" ref="versionSelectRef">
             <el-option v-for="item in versions" :key="item.id" :label="item.name" :value="item.id">el-option>
       el-select>
el-form-item>
const versionSelectRef = ref<InstanceType<typeof ElSelect>>();
//获取下拉框的label
const changeYear = async () => {
	props.ruleForm.versionName = versionSelectRef.value?.selectedLabel;
}

你可能感兴趣的:(elementui,前端,typescript)