admin管理员组文章数量:1402975
I'm trying to extend a vuetify ponent with some default props set in TypeScript. In JavaScript it worked perfectly but I can't figure out how to extend the ponents in TS. Here is the code for the Component in JS:
import { VTextField } from 'vuetify/lib'
export default {
name: "my-text-field",
extends: VTextField,
props: {
"hide-details": {
type: Boolean,
default: true
},
outlined: {
type: Boolean,
default: true
},
dense: {
type: Boolean,
default: true
},
"single-line": {
type: Boolean,
default: true
},
color: {
type: String,
default: "secondary"
}
}
}
I'm trying to extend a vuetify ponent with some default props set in TypeScript. In JavaScript it worked perfectly but I can't figure out how to extend the ponents in TS. Here is the code for the Component in JS:
import { VTextField } from 'vuetify/lib'
export default {
name: "my-text-field",
extends: VTextField,
props: {
"hide-details": {
type: Boolean,
default: true
},
outlined: {
type: Boolean,
default: true
},
dense: {
type: Boolean,
default: true
},
"single-line": {
type: Boolean,
default: true
},
color: {
type: String,
default: "secondary"
}
}
}
Share
Improve this question
asked Apr 28, 2020 at 9:33
Y. RamozY. Ramoz
671 silver badge9 bronze badges
3 Answers
Reset to default 4The proper way to do that add in the tsconfig.json
// tsconfig.json
{
"pilerOptions": {
"types": ["vuetify"]
}
}
Now just extend the needful ponent.
<script lang="ts">
import { VTextField } from 'vuetify/lib'
import { Component, Prop } from 'vue-property-decorator'
@Component({})
export default class TextField extends VTextField {
@Prop({default: 'auto'}) private hideDetails!: boolean|string;
@Prop({default: true}) private outlined!: boolean;
@Prop({default: true}) private dense!: boolean
@Prop({default: true}) private singleLine!: boolean;
@Prop({default: 'secondary'}) private color!: string
}
</script>
I've found a solution by peeking into the VTextArea ponent of Vuetify. Here's my solution:
import Vue from 'vue'
//@ts-ignore
import VTextField from 'vuetify/lib/ponents/VTextField/VTextField'
// Create Base Mixins and Define Custom Properties
const base = Vue.extend({ mixins: [VTextField] })
export default base.extend({
name: "my-text-field",
props: {
hideDetails: {
type: Boolean,
default: true
},
outlined: {
type: Boolean,
default: true
},
dense: {
type: Boolean,
default: true
},
singleLine: {
type: Boolean,
default: true
},
color: {
type: String,
default: "secondary"
}
}
})
hope this works for you:
import {Vue, Component, Prop} from 'vue-property-decorator';
import { VIcon, VTextField} from 'vuetify/lib'
interface Item {
text: string;
plete: boolean;
}
@Component({
name: 'TodoItem',
ponents: {
'v-icon': VIcon,
'v-text-field': VTextField
}
})
export default class TodoItem extends Vue {
@Prop(Object) public item!: Item;
@Prop(Number) public index!: number;
@Prop(Number) public editingId!: number;
public editingContent = 'nihao';
public edit() {
this.$emit('on-edit', this.index)
}
public save() {
alert('k');
}
protected render() {
return (
<li>
{this.editingId === this.index ?
(<div>
{/* tslint:disable-next-line:max-line-length */}
<v-text-field v-model={this.editingContent} append-icon={'mdi-close'} placeholder={this.item.text} on-click:append={this.save}/>
{/*<v-text-field><v-icon color={'red'} slot={'append'}>mdi-close</v-icon></v-text-field>*/}
</div>)
: (<div>
<span>{this.item.text}</span>
<v-icon x-small={true} nativeOn-click={this.edit}>mdi-pencil</v-icon>
</div>)
}
</li>
);
}
}
本文标签: javascriptExtend Vuetify components in TypeScriptStack Overflow
版权声明:本文标题:javascript - Extend Vuetify components in TypeScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744124052a2591872.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论