|
|
@@ -22,42 +22,140 @@ app.use(SearchBar);
|
|
|
### 基础用法
|
|
|
|
|
|
```html
|
|
|
-<nut-searchbar class="wrap" v-model="searchValue" @search="search">
|
|
|
+ <nut-searchbar v-model="searchValue"></nut-searchbar>
|
|
|
+```
|
|
|
+
|
|
|
+```javascript
|
|
|
+ import { toRefs, reactive } from 'vue';
|
|
|
+
|
|
|
+ export default {
|
|
|
+ setup() {
|
|
|
+ const state = reactive({
|
|
|
+ searchValue: ""
|
|
|
+ });
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...toRefs(state),
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+```
|
|
|
+
|
|
|
+### 搜索事件监听
|
|
|
+
|
|
|
+```html
|
|
|
+ <nut-searchbar v-model="searchValue" @search="search"></nut-searchbar>
|
|
|
+```
|
|
|
+
|
|
|
+```javascript
|
|
|
+ import { toRefs, reactive } from 'vue';
|
|
|
+ import { Toast } from '@nutui/nutui';
|
|
|
+
|
|
|
+ export default {
|
|
|
+ setup() {
|
|
|
+ const state = reactive({
|
|
|
+ searchValue: ""
|
|
|
+ });
|
|
|
+
|
|
|
+ const search = function () {
|
|
|
+ Toast.text('搜索触发');
|
|
|
+ };
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...toRefs(state),
|
|
|
+ search,
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+```
|
|
|
+
|
|
|
+### 显示搜索 icon
|
|
|
+
|
|
|
+```html
|
|
|
+ <nut-searchbar v-model="searchValue" :has-left-in="true">
|
|
|
+ <template v-slot:leftin>
|
|
|
+ <nut-icon size="14" name="search2"></nut-icon>
|
|
|
+ </template>
|
|
|
+ </nut-searchbar>
|
|
|
+```
|
|
|
+
|
|
|
+```javascript
|
|
|
+ import { toRefs, reactive } from 'vue';
|
|
|
+ import { Icon } from '@nutui/nutui';
|
|
|
+
|
|
|
+ export default {
|
|
|
+ setup() {
|
|
|
+ const state = reactive({
|
|
|
+ searchValue: ""
|
|
|
+ });
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...toRefs(state),
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+```
|
|
|
+
|
|
|
+### 右侧添加搜索文字
|
|
|
+
|
|
|
+```html
|
|
|
+ <nut-searchbar v-model="searchValue" :has-right-out="true">
|
|
|
+ <template v-slot:rightout>
|
|
|
+ 搜索
|
|
|
+ </template>
|
|
|
+ </nut-searchbar>
|
|
|
+```
|
|
|
+
|
|
|
+```javascript
|
|
|
+ import { toRefs, reactive } from 'vue';
|
|
|
+
|
|
|
+ export default {
|
|
|
+ setup() {
|
|
|
+ const state = reactive({
|
|
|
+ searchValue: ""
|
|
|
+ });
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...toRefs(state),
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+```
|
|
|
+
|
|
|
+### 显示全部 icon
|
|
|
+
|
|
|
+```html
|
|
|
+ <nut-searchbar v-model="searchValue" :has-left-in="true" :has-left-out="true" :has-right-in="true" :has-right-out="true">
|
|
|
<template v-slot:leftout>
|
|
|
- <nut-icon @click="clickLeft" size="20" name="left"></nut-icon>
|
|
|
+ <nut-icon @click="clickLeft" size="20" name="left"></nut-icon>
|
|
|
</template>
|
|
|
<template v-slot:leftin>
|
|
|
- <nut-icon size="14" name="search2"></nut-icon>
|
|
|
+ <nut-icon size="14" name="search2"></nut-icon>
|
|
|
</template>
|
|
|
<template v-slot:rightin>
|
|
|
- <nut-icon size="20" name="photograph"></nut-icon>
|
|
|
+ <nut-icon size="20" name="photograph"></nut-icon>
|
|
|
</template>
|
|
|
<template v-slot:rightout>
|
|
|
- <nut-icon size="20" name="message"></nut-icon>
|
|
|
+ <nut-icon size="20" name="message"></nut-icon>
|
|
|
</template>
|
|
|
-</nut-searchbar>
|
|
|
+ </nut-searchbar>
|
|
|
```
|
|
|
|
|
|
```javascript
|
|
|
- setup() {
|
|
|
- const state = reactive({
|
|
|
- searchValue: ""
|
|
|
- });
|
|
|
+ import { toRefs, reactive } from 'vue';
|
|
|
+ import { Icon } from '@nutui/nutui';
|
|
|
|
|
|
- const search = function () {
|
|
|
- console.log('ENTER clicked');
|
|
|
- }
|
|
|
+ export default {
|
|
|
+ setup() {
|
|
|
+ const state = reactive({
|
|
|
+ searchValue: ""
|
|
|
+ });
|
|
|
|
|
|
- const clickLeft = function () {
|
|
|
- console.log('left clicked');
|
|
|
+ return {
|
|
|
+ ...toRefs(state),
|
|
|
+ };
|
|
|
}
|
|
|
-
|
|
|
- return {
|
|
|
- clickLeft,
|
|
|
- search,
|
|
|
- ...toRefs(state),
|
|
|
- };
|
|
|
-}
|
|
|
+ }
|
|
|
```
|
|
|
|
|
|
### Props
|
|
|
@@ -68,10 +166,10 @@ app.use(SearchBar);
|
|
|
| input-type | 输入框类型 | String | 'text' |
|
|
|
| placeholder | 输入框默认暗纹 | String | '请输入' |
|
|
|
| clearable | 是否展示清除按钮 | Boolean | true |
|
|
|
-| has-left-in | 是否展示输入框内 左icon | Boolean | true |
|
|
|
-| has-left-out | 是否展示输入框外 左icon | Boolean | true |
|
|
|
-| has-right-in | 是否展示输入框内 右icon | Boolean | true |
|
|
|
-| has-right-out | 是否展示输入框外 右icon | Boolean | true |
|
|
|
+| has-left-in | 是否展示输入框内 左icon | Boolean | false |
|
|
|
+| has-left-out | 是否展示输入框外 左icon | Boolean | false |
|
|
|
+| has-right-in | 是否展示输入框内 右icon | Boolean | false |
|
|
|
+| has-right-out | 是否展示输入框外 右icon | Boolean | false |
|
|
|
|
|
|
### Events
|
|
|
|