current position:Home>Vue2 simple use of vant (based on Vue CLI)
Vue2 simple use of vant (based on Vue CLI)
2022-04-29 16:33:55【chy】
1.vant Installation
npm install
Use in existing projects vant when , Can pass npm
or yarn
Installation .vue2 and vue3 The installation method is basically the same
npm i vant -S # Install the latest version
npm i [email protected] -S # vue2 project , install vant2
Copy code
Through scaffolding UI install
If you pass vue Official scaffolding Vue Cli If you create a project
It can be installed in the following positions
Import components
There are three ways of introduction, namely
- Auto on demand import
- Manual on-demand import
- Introduce all
1. Automatically bring in components on demand
The official recommendation
A plug-in needs to be installed :
babel-plugin-import Is a babel plug-in unit , It will... During compilation import The way of writing is automatically converted to the way of introducing on demand . Can pass npm Mode of installation :npm i babel-plugin-import -D
Use babel7 Can be in babel.config.js Middle configuration
module.exports = {
plugins: [
['import', {
libraryName: 'vant',
libraryDirectory: 'es',
style: true
}, 'vant']
]
};
Copy code
stay main.js Introduce the desired components in .( Use button Make an introduction )
import { Button } from 'vant' // introduce Button Components
Vue.use(Button) // Global registration
Copy code
( If you don't understand, you can look at the picture )
So you can use... In components or pages button Component
2. Manually bring in components on demand
Without plug-ins , You can manually import the required components , Also use button give an example
stay main.js Introduction in
import Button from 'vant/lib/button';
import 'vant/lib/button/style';
Vue.use(Button) // Global registration button
Copy code
3. Import all components
Vant All components can be imported at one time , Introducing all the components increases the size of the code package , So it's not recommended .
Also in main.js Introduction in
import Vue from 'vue';
import Vant from 'vant';
import 'vant/lib/index.css';
Vue.use(Vant);
Copy code
Be careful : After configuring on-demand import , Direct import of all components is not allowed .
take babel.config.js Code comments in
2 vant Simple use
stay vant Of Official documents The usage of various components is described in detail in .
button Button
Button support default
、primary
、info
、warning
、danger
Five types , The default is default
.
<van-button type="primary"> Main buttons </van-button>
<van-button type="info"> Information buttons </van-button>
<van-button type="default"> Default button </van-button>
<van-button type="warning"> Warning button </van-button>
<van-button type="danger"> Danger button </van-button>
Copy code
Simple button
adopt plain Property to set the button to a plain button
<van-button plain type="primary"> Simple button </van-button>
<van-button plain type="info"> Simple button </van-button>
Copy code
In addition to these styles, there are many other functions
Webpage navigation
Can pass url
Attributes in URL Jump , Or through to
Property to perform route jump .
<van-button type="primary" url="/vant/mobile.html">URL Jump </van-button>
<van-button type="primary" to="index"> Routing jump </van-button>
Copy code
The details of the props Events Slots And style variables (less) It can be in the corresponding component file Find below
summary
- vant install
- vant Easy to use
This article briefly introduces vant stay vue2 Simple installation and simple use . More ways to use components can be found in vant official file View in
copyright notice
author[chy],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/04/202204291633513155.html
The sidebar is recommended
- HTTP becomes HTTPS, self-made certificate
- Web front-end operation - tourism enterprise marketing publicity responsive website template (HTML + CSS + JavaScript)
- Self inspection list of a [qualified] front-end Engineer
- This principle in JavaScript and six common usage scenarios
- JavaScript this priority
- Analyzing the principle of HTTPS encryption
- Difference and principle between websocket and http
- Use of elementui scroll bar component El scrollbar
- Nginx security optimization
- GAC group has become the first pilot enterprise of "yueyouhang". Blessed are the car owners in Guangdong!
guess what you like
Loki HTTP API usage
JavaScript - prototype, prototype chain
Front end experience
JavaScript -- Inheritance
HTTP cache
Filters usage of table in elementui
A JavaScript pit encountered by a non front-end siege lion
Grain College - image error when writing Vue with vscode
Utility gadget - get the IP address in the HTTP request
Could not fetch URL https://pypi.org/simple/pytest-html/: There was a problem confirming the ssl cer
Random recommended
- Function of host parameter in http
- Use nginx proxy node red under centos7 and realize password access
- Centos7 nginx reverse proxy TCP port
- In eclipse, an error is reported when referencing layuijs and CSS
- Front end online teacher Pink
- Learn to use PHP to insert elements at the specified position and key of the array
- Learn how to use HTML and CSS styles to overlay two pictures on another picture to achieve the effect of scanning QR code by wechat
- Learn how to use CSS to vertically center the content in Div
- Learn how to use CSS to circle numbers
- Learn to open and display PDF files in HTML web pages
- The PHP array random sorting function shuffle() randomly scrambles the order of array elements
- JQuery implements the keyboard enter search function
- 16 ArcGIS API for JavaScript 4.18 a new development method based on ES modules @ ArcGIS / core
- 17 ArcGIS API for JavaScript 4.18 draw points, lines and faces with the mouse
- 18 ArcGIS API for JavaScript 4.18 obtain the length and area after drawing line segments and surface features
- Vue environment construction -- scaffold
- Build a demo with Vue scaffold
- Using vuex in Vue projects
- Use Vue router in Vue project
- 26 [react basics-5] react hook
- 07 Chrome browser captures hover element style
- WebGIS development training (ArcGIS API for JavaScript)
- Solution to the blank page of the project created by create react app after packaging
- 19. Html2canvas implements ArcGIS API for JavaScript 4 X screenshot function
- Introduction to JavaScript API for ArcGIS 13
- Development of ArcGIS API for JavaScript under mainstream front-end framework
- Nginx learning notes
- Less learning notes tutorial
- Vue2 cannot get the value in props in the data of the child component, or it is always the default value (the value of the parent component comes from asynchrony)
- LeetCode 217. Determine whether there are duplicate elements in the array
- I'll write a website collection station myself. Do you think it's ok? [HTML + CSS + JS] Tan Zi
- Front end browser debugging tips
- Application of anti chattering and throttling in JavaScript
- How to create JavaScript custom events
- Several ways of hiding elements in CSS
- node. Js-3 step out the use of a server and express package
- CSS matrix function
- Fastapi series - synchronous and asynchronous mutual conversion processing practice
- How to extend the functionality of Axios without interceptors
- Read pseudo classes and pseudo elements