/*! For license information please see 7302.f3a38443.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["7302"],{47046:function(s,n,a){"use strict";a.r(n);var e=a("80681");let t=["innerHTML"];n.default={setup:()=>({html:""}),render:()=>((0,e.wg)(),(0,e.iD)("div",{class:"van-doc-markdown-body",innerHTML:'

Upgrade from v2 to v3

\n

Introduction

\n

This document provides an upgrade guide from Vant 2 to Vant 3.

\n

Upgrade steps

\n

1. Upgrade to Vue 3

\n

Vant 3 is developed based on Vue 3. Before using Vant 3, please upgrade the Vue in the project to version 3.0 or above.

\n

2. Handle incompatible changes

\n

There are some incompatible changes from Vant 2 to Vant 3, please read the incompatible changes below carefully and deal with them in order.

\n

Incompatible changes

\n

Component renaming

\n

The GoodsAction component is renamed to ActionBar.

\n
<!-- Vant 2 -->\n<van-goods-action>\n  <van-goods-action-icon text="icon" />\n  <van-goods-action-button text="button" />\n</van-goods-action>\n\n<!-- Vant 3 -->\n<van-action-bar>\n  <van-action-bar-icon text="icon" />\n  <van-action-bar-button text="button" />\n</van-action-bar>\n
\n

Deprecated components

\n

Vant v3 removed the SwitchCell component, you can use the Cell and Switch components instead.

\n
<!-- Vant 2 -->\n<van-switch-cell title="title" v-model="checked" />\n\n<!-- Vant 3 -->\n<van-cell center title="title">\n  <template #right-icon>\n    <van-switch v-model="checked" size="24" />\n  </template>\n</van-cell>\n
\n
\n

In order to adapt to Vue 3\'s v-model API usage changes, all components that provide v-model have some adjustments in usage. v-model for the following popup components has been renamed to v-model:show:

\n\n
<!-- Vant 2 -->\n<van-popup v-model="show" />\n\n<!-- Vant 3 -->\n<van-popup v-model:show="show" />\n
\n

Form component v-model internal value change

\n

The prop corresponding to the following form component v-model is renamed to modelValue, and the event is renamed to update:modelValue:

\n

-Checkbox

\n\n
<!-- Vant 2 -->\n<van-field :value="value" @input="onInput" />\n\n<!-- Vant 3 -->\n<van-field :model-value="value" @update:model-value="onInput" />\n
\n

Other v-model tweaks

\n\n

Badge prop adjustment

\n

In the previous version, we used the info prop to display the badge in the upper right corner of the icon. In order to better meet the naming habits of the community, we renamed this prop to badge, which affects the following components:

\n\n

At the same time, the Info component will also be renamed to Badge.

\n
<!-- Vant 2 -->\n<van-icon info="5" />\n\n<!-- Vant 3 -->\n<van-icon badge="5" />\n
\n

Rename the get-container prop

\n

Vue 3.0 added a new Teleport component, which provides the ability to render the component to any DOM position, and Vant 2 also provides similar capabilities through the get-container prop. For consistency with the official API, the get-container prop in Vant 3 will be renamed to teleport.

\n
<!-- Vant 2 -->\n<template>\n  <van-popup get-container="body" />\n  <van-popup :get-container="getContainer" />\n</template>\n<script>\n  export default {\n    methods: {\n      getContainer() {\n        return document.querySelector('#container');\n      },\n    },\n  };\n</script>\n\n<!-- Vant 3 -->\n<template>\n  <van-popup teleport="body" />\n  <van-popup :teleport="container" />\n</template>\n<script>\n  export default {\n    beforeCreate() {\n      this.container = document.querySelector('#container');\n    },\n  };\n</script>\n
\n

API adjustments

\n

Area

\n\n

Button

\n\n

Checkbox

\n\n

Dialog

\n\n

DatetimePicker

\n\n

ImagePreview

\n\n

Picker

\n\n

Popover

\n\n

Stepper

\n\n

SwipeCell

\n\n

Toast

\n\n

TreeSelect

\n\n

Global methods

\n

Global methods such as $toast and $dialog are provided by default in Vant 2, but Vue 3.0 no longer supports directly mounting methods on Vue\'s prototype chain, so starting from Vant 3.0, you must first pass app.use registers the component to the corresponding app.

\n
import { Toast, Dialog, Notify } from 'vant';\n\n// Register components such as Toast to the app\napp.use(Toast);\napp.use(Dialog);\napp.use(Notify);\n\n// Subcomponents in the app can directly call methods such as $toast\nexport default {\n  mounted() {\n    this.$toast('prompt text');\n  },\n};\n
\n
'},null,8,t))}}}]);