mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 02:41:46 +08:00
chore: remove all mixin
This commit is contained in:
parent
3142266768
commit
c2f4165d0f
@ -1,33 +0,0 @@
|
|||||||
/**
|
|
||||||
* Bind event when mounted or activated
|
|
||||||
*/
|
|
||||||
import { on, off } from '../utils/dom/event';
|
|
||||||
|
|
||||||
type BindEventMixinThis = {
|
|
||||||
binded: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
type BindEventHandler = (bind: typeof on | typeof off, isBind: boolean) => void;
|
|
||||||
|
|
||||||
export function BindEventMixin(handler: BindEventHandler) {
|
|
||||||
function bind(this: BindEventMixinThis) {
|
|
||||||
if (!this.binded) {
|
|
||||||
handler.call(this, on, true);
|
|
||||||
this.binded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function unbind(this: BindEventMixinThis) {
|
|
||||||
if (this.binded) {
|
|
||||||
handler.call(this, off, false);
|
|
||||||
this.binded = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
mounted: bind,
|
|
||||||
activated: bind,
|
|
||||||
deactivated: unbind,
|
|
||||||
beforeUnmount: unbind,
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
import { FIELD_KEY } from '../field';
|
|
||||||
|
|
||||||
export const FieldMixin = {
|
|
||||||
inject: {
|
|
||||||
vanField: {
|
|
||||||
from: FIELD_KEY,
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
watch: {
|
|
||||||
modelValue() {
|
|
||||||
const field = this.vanField;
|
|
||||||
|
|
||||||
if (field) {
|
|
||||||
field.resetValidation();
|
|
||||||
field.validateWithTrigger('onChange');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
created() {
|
|
||||||
const field = this.vanField;
|
|
||||||
|
|
||||||
if (field && !field.childFieldValue.value) {
|
|
||||||
field.childFieldValue.value = () => this.modelValue;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
@ -1,67 +0,0 @@
|
|||||||
export function ChildrenMixin(parent, options = {}) {
|
|
||||||
const indexKey = options.indexKey || 'index';
|
|
||||||
|
|
||||||
return {
|
|
||||||
inject: {
|
|
||||||
// TODO: disableBindRelation
|
|
||||||
parent: {
|
|
||||||
from: parent,
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
|
||||||
[indexKey]() {
|
|
||||||
this.bindRelation();
|
|
||||||
|
|
||||||
if (this.parent) {
|
|
||||||
return this.parent.children.indexOf(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
mounted() {
|
|
||||||
this.bindRelation();
|
|
||||||
},
|
|
||||||
|
|
||||||
beforeUnmount() {
|
|
||||||
if (this.parent) {
|
|
||||||
this.parent.children = this.parent.children.filter(
|
|
||||||
(item) => item !== this
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
bindRelation() {
|
|
||||||
if (!this.parent || this.parent.children.indexOf(this) !== -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const children = [...this.parent.children, this];
|
|
||||||
|
|
||||||
// TODO sortChildren
|
|
||||||
|
|
||||||
this.parent.children = children;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ParentMixin(parent) {
|
|
||||||
return {
|
|
||||||
provide() {
|
|
||||||
return {
|
|
||||||
[parent]: this,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
children: [],
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user