docs(Notify): use composition api

This commit is contained in:
chenjiahan 2020-12-13 16:58:10 +08:00
parent 65e14cd84a
commit 57c860afb8
3 changed files with 92 additions and 73 deletions

View File

@ -65,19 +65,23 @@ export default {
```
```js
import { ref } from 'vue';
export default {
data() {
return {
show: false,
};
},
methods: {
showNotify() {
this.show = true;
setup() {
const show = ref(false);
const showNotify = () => {
show.value = true;
setTimeout(() => {
this.show = false;
show.value = false;
}, 2000);
},
};
return {
show,
showNotify,
};
},
};
```

View File

@ -102,19 +102,23 @@ export default {
```
```js
import { ref } from 'vue';
export default {
data() {
return {
show: false,
};
},
methods: {
showNotify() {
this.show = true;
setup() {
const show = ref(false);
const showNotify = () => {
show.value = true;
setTimeout(() => {
this.show = false;
show.value = false;
}, 2000);
},
};
return {
show,
showNotify,
};
},
};
```

View File

@ -23,15 +23,18 @@
<van-cell is-link :title="t('componentCall')" @click="showComponentCall" />
<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>
</van-notify>
</demo-block>
</template>
<script>
export default {
i18n: {
<script lang="ts">
import { ref } from 'vue';
import { useTranslate } from '@demo/use-translate';
import Notify from '..';
const i18n = {
'zh-CN': {
primary: '主要通知',
success: '成功通知',
@ -56,47 +59,55 @@ export default {
componentCall: 'Component Call',
customDuration: 'Custom Duration',
},
},
data() {
return {
show: false,
};
},
methods: {
showNotify() {
this.$notify(this.t('content'));
},
export default {
data() {
const t = useTranslate(i18n);
const show = ref(false);
showCustomColor() {
this.$notify({
message: this.t('customColor'),
const showNotify = () => {
Notify(t('content'));
};
const showCustomColor = () => {
Notify({
color: '#ad0000',
message: t('customColor'),
background: '#ffe1e1',
});
},
};
showCustomDuration() {
this.$notify({
message: this.t('customDuration'),
const showCustomDuration = () => {
Notify({
message: t('customDuration'),
duration: 1000,
});
},
};
showType(type) {
this.$notify({
message: this.t('content'),
const showType = (type: string) => {
Notify({
message: t('content'),
type,
});
},
};
showComponentCall() {
this.show = true;
const showComponentCall = () => {
show.value = true;
setTimeout(() => {
this.show = false;
show.value = false;
}, 2000);
},
};
return {
t,
show,
showType,
showNotify,
showCustomColor,
showComponentCall,
showCustomDuration,
};
},
};
</script>