mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-03-01 13:36:55 +08:00
modify(customAdd): organize the code
This commit is contained in:
parent
a81c970704
commit
1012610d32
@ -1,21 +1,23 @@
|
||||
# Basic
|
||||
```html
|
||||
<n-custom-add
|
||||
v-model="test1"
|
||||
v-model="test"
|
||||
placeholder-key="placeholder1"
|
||||
placeholder-value="placeholder2"
|
||||
/>
|
||||
<pre>
|
||||
{{ JSON.stringify(test,0,2) }}
|
||||
</pre>
|
||||
```
|
||||
```js
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
test1: [
|
||||
test: [
|
||||
{
|
||||
key: 'key1',
|
||||
value: 'value1'
|
||||
},
|
||||
{}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Custom
|
||||
```html
|
||||
<n-custom-add
|
||||
v-model="test1"
|
||||
v-model="test"
|
||||
title="Add CheckBox"
|
||||
>
|
||||
<template v-slot="slotProps">
|
||||
@ -21,12 +21,15 @@
|
||||
</div>
|
||||
</template>
|
||||
</n-custom-add>
|
||||
<pre>
|
||||
{{ JSON.stringify(test,0,2) }}
|
||||
</pre>
|
||||
```
|
||||
```js
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
test1: [
|
||||
test: [
|
||||
{
|
||||
isCheck: true
|
||||
}
|
||||
|
@ -1,16 +1,19 @@
|
||||
# 基础用法
|
||||
```html
|
||||
<n-custom-add
|
||||
v-model="test1"
|
||||
v-model="test"
|
||||
placeholder-key="placeholder1"
|
||||
placeholder-value="placeholder2"
|
||||
/>
|
||||
<pre>
|
||||
{{ JSON.stringify(test,0,2) }}
|
||||
</pre>
|
||||
```
|
||||
```js
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
test1: [
|
||||
test: [
|
||||
{
|
||||
key: 'key1',
|
||||
value: 'value1'
|
||||
|
@ -21,6 +21,9 @@
|
||||
</div>
|
||||
</template>
|
||||
</n-custom-add>
|
||||
<pre>
|
||||
{{ JSON.stringify(test,0,2) }}
|
||||
</pre>
|
||||
```
|
||||
```js
|
||||
export default {
|
||||
|
@ -34,10 +34,10 @@ You can custom you valiation by setting custom trigger in rules.
|
||||
<n-input-number v-model="slotProps.item.inputNumberValue"/>
|
||||
</n-form-item>
|
||||
<n-form-item
|
||||
:path="'group.' + slotProps.index + '.test'"
|
||||
rule-path="group.test"
|
||||
:path="'group.' + slotProps.index + '.input'"
|
||||
rule-path="group.input"
|
||||
>
|
||||
<n-input v-model="slotProps.item.test"/>
|
||||
<n-input v-model="slotProps.item.input"/>
|
||||
</n-form-item>
|
||||
</div>
|
||||
</template>
|
||||
@ -72,9 +72,8 @@ export default {
|
||||
],
|
||||
group: [
|
||||
{
|
||||
isCheck: true,
|
||||
// num: null,
|
||||
// string: null
|
||||
inputNumberValue: null,
|
||||
input: null
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -130,7 +129,7 @@ export default {
|
||||
trigger: ['blur', 'change'],
|
||||
message: 'Please input a number which is not zero'
|
||||
},
|
||||
test: {
|
||||
input: {
|
||||
required: true,
|
||||
message: 'Please input your key',
|
||||
trigger: ['input', 'blur']
|
||||
@ -163,7 +162,6 @@ export default {
|
||||
return value === this.model.password
|
||||
},
|
||||
validateGroupNumber (rule, value) {
|
||||
console.log('value',value)
|
||||
return value !== 0
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
<template>
|
||||
<div
|
||||
ref="default"
|
||||
class="n-custom-add-pair"
|
||||
>
|
||||
<n-form-item v-if="NCustomAdd.NFormItem" :path="path + '.key'" :rule-path="parentPath + '.key'">
|
||||
@ -66,54 +65,6 @@ export default {
|
||||
type: String,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
labels: [
|
||||
{
|
||||
key: 'key1',
|
||||
value: 'value1'
|
||||
},
|
||||
{
|
||||
key: 'key2',
|
||||
value: 'value2'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
arrayValue: {
|
||||
get () {
|
||||
return this.NCustomAdd.value
|
||||
},
|
||||
set (value) {
|
||||
this.$emit('change-value', value)
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
add () {
|
||||
this.$emit('on-add')
|
||||
this.$set(this.arrayValue, this.arrayValue.length, {})
|
||||
},
|
||||
remove (index) {
|
||||
this.$emit('on-remove', index)
|
||||
if (index === 0 && this.arrayValue.length <= 1) {
|
||||
Object.keys(this.arrayValue[0]).forEach((key) => {
|
||||
let type = typeof (this.arrayValue[0][key])
|
||||
switch (type) {
|
||||
case 'boolean':
|
||||
this.$set(this.arrayValue[0], key, false)
|
||||
break
|
||||
default:
|
||||
this.$set(this.arrayValue[0], key, null)
|
||||
break
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
this.arrayValue.splice(index, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -98,26 +98,6 @@ export default {
|
||||
default: 'Value'
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
labels: [
|
||||
{
|
||||
key: 'key1',
|
||||
value: 'value1'
|
||||
},
|
||||
{
|
||||
key: 'key2',
|
||||
value: 'value2'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
parentPath () {
|
||||
return this.NFormItem.path
|
||||
}
|
||||
|
||||
},
|
||||
methods: {
|
||||
changeValue (value) {
|
||||
this.value = value
|
||||
|
@ -40,7 +40,9 @@
|
||||
}
|
||||
}
|
||||
@include b(custom-add-pair-input){
|
||||
margin-right: 13px;
|
||||
&:first-child {
|
||||
margin-right: 13px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user