mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-24 15:39:15 +08:00
docs(Notify): use composition api
This commit is contained in:
parent
65e14cd84a
commit
57c860afb8
@ -65,19 +65,23 @@ export default {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const show = ref(false);
|
||||||
show: false,
|
|
||||||
};
|
const showNotify = () => {
|
||||||
},
|
show.value = true;
|
||||||
methods: {
|
|
||||||
showNotify() {
|
|
||||||
this.show = true;
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.show = false;
|
show.value = false;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
show,
|
||||||
|
showNotify,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -102,19 +102,23 @@ export default {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const show = ref(false);
|
||||||
show: false,
|
|
||||||
};
|
const showNotify = () => {
|
||||||
},
|
show.value = true;
|
||||||
methods: {
|
|
||||||
showNotify() {
|
|
||||||
this.show = true;
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.show = false;
|
show.value = false;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
show,
|
||||||
|
showNotify,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -23,80 +23,91 @@
|
|||||||
<van-cell is-link :title="t('componentCall')" @click="showComponentCall" />
|
<van-cell is-link :title="t('componentCall')" @click="showComponentCall" />
|
||||||
|
|
||||||
<van-notify v-model:show="show" type="success">
|
<van-notify v-model:show="show" type="success">
|
||||||
<van-icon name="bell" style="margin-right: 4px;" />
|
<van-icon name="bell" style="margin-right: 4px" />
|
||||||
<span>{{ t('content') }}</span>
|
<span>{{ t('content') }}</span>
|
||||||
</van-notify>
|
</van-notify>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script lang="ts">
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { useTranslate } from '@demo/use-translate';
|
||||||
|
import Notify from '..';
|
||||||
|
|
||||||
|
const i18n = {
|
||||||
|
'zh-CN': {
|
||||||
|
primary: '主要通知',
|
||||||
|
success: '成功通知',
|
||||||
|
danger: '危险通知',
|
||||||
|
warning: '警告通知',
|
||||||
|
content: '通知内容',
|
||||||
|
notifyType: '通知类型',
|
||||||
|
customColor: '自定义颜色',
|
||||||
|
customNotify: '自定义配置',
|
||||||
|
componentCall: '组件调用',
|
||||||
|
customDuration: '自定义时长',
|
||||||
|
},
|
||||||
|
'en-US': {
|
||||||
|
primary: 'Primary',
|
||||||
|
success: 'Success',
|
||||||
|
danger: 'Danger',
|
||||||
|
warning: 'Warning',
|
||||||
|
content: 'Notify Message',
|
||||||
|
notifyType: 'Notify Type',
|
||||||
|
customColor: 'Custom Color',
|
||||||
|
customNotify: 'Custom Notify',
|
||||||
|
componentCall: 'Component Call',
|
||||||
|
customDuration: 'Custom Duration',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
i18n: {
|
|
||||||
'zh-CN': {
|
|
||||||
primary: '主要通知',
|
|
||||||
success: '成功通知',
|
|
||||||
danger: '危险通知',
|
|
||||||
warning: '警告通知',
|
|
||||||
content: '通知内容',
|
|
||||||
notifyType: '通知类型',
|
|
||||||
customColor: '自定义颜色',
|
|
||||||
customNotify: '自定义配置',
|
|
||||||
componentCall: '组件调用',
|
|
||||||
customDuration: '自定义时长',
|
|
||||||
},
|
|
||||||
'en-US': {
|
|
||||||
primary: 'Primary',
|
|
||||||
success: 'Success',
|
|
||||||
danger: 'Danger',
|
|
||||||
warning: 'Warning',
|
|
||||||
content: 'Notify Message',
|
|
||||||
notifyType: 'Notify Type',
|
|
||||||
customColor: 'Custom Color',
|
|
||||||
customNotify: 'Custom Notify',
|
|
||||||
componentCall: 'Component Call',
|
|
||||||
customDuration: 'Custom Duration',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
const t = useTranslate(i18n);
|
||||||
show: false,
|
const show = ref(false);
|
||||||
|
|
||||||
|
const showNotify = () => {
|
||||||
|
Notify(t('content'));
|
||||||
};
|
};
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
const showCustomColor = () => {
|
||||||
showNotify() {
|
Notify({
|
||||||
this.$notify(this.t('content'));
|
|
||||||
},
|
|
||||||
|
|
||||||
showCustomColor() {
|
|
||||||
this.$notify({
|
|
||||||
message: this.t('customColor'),
|
|
||||||
color: '#ad0000',
|
color: '#ad0000',
|
||||||
|
message: t('customColor'),
|
||||||
background: '#ffe1e1',
|
background: '#ffe1e1',
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
showCustomDuration() {
|
const showCustomDuration = () => {
|
||||||
this.$notify({
|
Notify({
|
||||||
message: this.t('customDuration'),
|
message: t('customDuration'),
|
||||||
duration: 1000,
|
duration: 1000,
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
showType(type) {
|
const showType = (type: string) => {
|
||||||
this.$notify({
|
Notify({
|
||||||
message: this.t('content'),
|
message: t('content'),
|
||||||
type,
|
type,
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
showComponentCall() {
|
const showComponentCall = () => {
|
||||||
this.show = true;
|
show.value = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.show = false;
|
show.value = false;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
t,
|
||||||
|
show,
|
||||||
|
showType,
|
||||||
|
showNotify,
|
||||||
|
showCustomColor,
|
||||||
|
showComponentCall,
|
||||||
|
showCustomDuration,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user