반응형
커스텀 프로펠러 타입 Vue.js
Vue.js 소품용으로 커스텀 소품 타입을 작성(검증을 통해 확장)할 수 있는 방법이 있습니까?
다음 예에서는 오브젝트 프로포트를 찾을 수 있습니다.background오브젝트 대신 커스텀 소품 타입의 이미지를 원합니다.이미지에서 확인 가능 여부src그리고.alt채워져 있고 나머지는 선택 사항입니다.
현재 제공 내용:
export default {
props: {
background: {
type: Object,
src: String,
srcset: String,
alt: String,
title: String,
},
},
};
갖고 싶은 것:
class customPropImage {
// magic ...
}
export default {
props: {
background: Image,
},
};
물론 넌 할 수 있어.Vue 설명서에 따르면 유형을 사용자 지정 유형의 생성자로 설정할 수 있습니다.커스텀 검증에서는, 다음과 같이 됩니다.
function CustomImage () {
// Magic
}
Vue.component('blog-post', {
props: {
myImage: {
type: CustomImage,
validator: function (value) {
return true; // or false based on value of myImage
}
}
}
})
Vue2에서의 커스텀 소품 타이핑
나에게 유효한 솔루션은 @vue/composition-api뿐입니다.
/* eslint-disable @typescript-eslint/no-empty-interface */
import { defineComponent } from '@vue/composition-api'
import { IAddress } from '@/types'
interface Props {
address: IAddress
title: string
}
declare module 'vue/types/vue' {
interface Vue extends Props {}
}
export default defineComponent({
props: {
address: Object,
title: String,
},
setup (props: Props) {
const address = props.address
console.log(address)
},
})
언급URL : https://stackoverflow.com/questions/53095850/custom-prop-type-vue-js
반응형
'programing' 카테고리의 다른 글
| Visual Studio C/C++ 콘솔 응용 프로그램에서 콘솔 창 닫힘 방지 (0) | 2022.08.03 |
|---|---|
| 잭슨 JSON과 휴지 상태 JPA의 무한 재귀 문제 (0) | 2022.08.03 |
| Java 설치를 위한 환경 변수 (0) | 2022.08.03 |
| 코드 분할 vuex 응용 프로그램 (0) | 2022.08.03 |
| Java에서 순차 정수 목록 또는 배열을 생성하려면 어떻게 해야 합니까? (0) | 2022.08.03 |