mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-24 15:39:15 +08:00
docs(Popup): use composition api
This commit is contained in:
parent
497a88d7bb
commit
2494c0aa0e
@ -20,17 +20,18 @@ app.use(Popup);
|
||||
```
|
||||
|
||||
```js
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
show: false,
|
||||
};
|
||||
},
|
||||
import { ref } from 'vue';
|
||||
|
||||
methods: {
|
||||
showPopup() {
|
||||
this.show = true;
|
||||
},
|
||||
export default {
|
||||
setup() {
|
||||
const show = ref(false);
|
||||
const showPopup = () => {
|
||||
show.value = true;
|
||||
};
|
||||
return {
|
||||
show,
|
||||
showPopup,
|
||||
};
|
||||
},
|
||||
};
|
||||
```
|
||||
@ -86,20 +87,23 @@ Use `position` prop to set popup display position.
|
||||
Use `teleport` prop to specify mount location.
|
||||
|
||||
```html
|
||||
<!-- mount to body -->
|
||||
<!-- teleport to body -->
|
||||
<van-popup v-model:show="show" teleport="body" />
|
||||
|
||||
<!-- mount to #app -->
|
||||
<!-- teleport to #app -->
|
||||
<van-popup v-model:show="show" teleport="#app" />
|
||||
|
||||
<!-- mount to Element -->
|
||||
<!-- teleport to Element -->
|
||||
<van-popup v-model:show="show" :teleport="myContainer" />
|
||||
```
|
||||
|
||||
```js
|
||||
export default {
|
||||
beforeCreate() {
|
||||
this.myContainer = document.querySelector('.my-container');
|
||||
setup() {
|
||||
const myContainer = document.querySelector('.my-container');
|
||||
return {
|
||||
myContainer,
|
||||
};
|
||||
},
|
||||
};
|
||||
```
|
||||
|
@ -26,17 +26,18 @@ app.use(Popup);
|
||||
```
|
||||
|
||||
```js
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
show: false,
|
||||
};
|
||||
},
|
||||
import { ref } from 'vue';
|
||||
|
||||
methods: {
|
||||
showPopup() {
|
||||
this.show = true;
|
||||
},
|
||||
export default {
|
||||
setup() {
|
||||
const show = ref(false);
|
||||
const showPopup = () => {
|
||||
show.value = true;
|
||||
};
|
||||
return {
|
||||
show,
|
||||
showPopup,
|
||||
};
|
||||
},
|
||||
};
|
||||
```
|
||||
@ -93,7 +94,7 @@ export default {
|
||||
|
||||
### 指定挂载位置
|
||||
|
||||
弹出层默认挂载到组件所在位置,可以通过 `teleport` 属性指定挂载位置。
|
||||
弹出层默认挂载到组件标签所在位置,可以通过 `teleport` 属性指定挂载位置。
|
||||
|
||||
```html
|
||||
<!-- 挂载到 body 节点下 -->
|
||||
@ -108,8 +109,11 @@ export default {
|
||||
|
||||
```js
|
||||
export default {
|
||||
beforeCreate() {
|
||||
this.myContainer = document.querySelector('.my-container');
|
||||
setup() {
|
||||
const myContainer = document.querySelector('.my-container');
|
||||
return {
|
||||
myContainer,
|
||||
};
|
||||
},
|
||||
};
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user