当前位置:网站首页>qs模块是?
qs模块是?
2022-07-17 00:07:00 【禾木白】
qs是可以用来将字符串解析和序列化字符串的库。
1.下载:
npm install -save qs
2.引入:
- 局部引入(使用的页面直接引入)
import qs from 'qs';
- 全局引入
vue2.0 中,入口文件main.js配置Vue.prototype挂载全局方法对象:
//引入:
import Vue from 'vue'
import Axios from 'axios'
import App from './App.vue'
// ...
/* 挂载全局对象 */
Vue.prototype.$http = Axios;
Vue.prototype.$qs = qs;
// ...
vue3. 中取消了Vue.prototype,在全局挂载方法和属性时,需要使用官方提供的globalPropertiesAPI。
//引入:
import { createApp } from 'vue''
import App from './App.vue'
import router from './router/index'
import axios from './utils/axios'
import qs from 'qs'
const app = createApp(App)
app.config.globalProperties.$axios = axios;
app.config.globalProperties.$qs = qs;
app.use(router)
app.mount('#app')3.使用:
vue2.0中使用 this.$qs
vue3.0中使用
import {reactive,toRefs,getCurrentInstance} from 'vue';
export default {
name:'Header',
setup() {
const { proxy } = getCurrentInstance()
const data = reactive({
name:'lili',
age:20,
address:{
provide:'河北省',
city:'沧州市',
newAdd:'北京市昌平区'
},
comData:[
{label:'111',value:1},
{label:'222',value:2},
{label:'333',value:3}
]
})
const getData=()=>{
let allData =proxy.$qs.stringify(data);
console.log(allData);
console.log(proxy.$qs.parse(allData))
}
return{
getData
}
},
mounted() {
this.getData();
},输出:
4.总结:
qs.parse() 将URL解析成对象的形式
qs. stringify() 将对象序列化成URL的形式以&进行拼接
边栏推荐
- Redis简单使用
- jsx 编译
- v-on的修饰符
- Text indent in uniapp doesn't work, and the indentation in the first line of uniapp doesn't work. How to solve it?
- Express的使用方法,路由的匹配与使用
- [SWPU 2019] network TTL encryption and some related knowledge
- Initial flask
- Uni app wechat applet - Mall (7) - Product Details
- Colorful text advertising code, text advertising code beautification version, add text advertising tutorials to the website
- Vue项目部署,清理缓存
猜你喜欢

JS intercepts the first few digits of the string or the last few digits of the string

wget 警告: 无法验证

Initial flask

VsCode建立非工程目录下的头文件自动查找

everything搜索不到startup_lpc11x.s文件

Day12 Association serialization processing

Express的使用方法,路由的匹配与使用

数据库连接池、sequelize实现增删改查等操作

Win10 vscode 代码格式化设置与远程断点调试
![Understand PHP from [Fifth space 2021] easycleanup_ session](/img/fc/95332d488dd6096f3a3f6a9fb11644.png)
Understand PHP from [Fifth space 2021] easycleanup_ session
随机推荐
JS string to object JS object to string JS string to object
Supplementary knowledge of attributes and methods of regular, JWT token, ronglianyun, celery, channel group, SKU, SPU, request object
“我的”Bug大全(转载)
使用redis - zset做排行榜
今天的码农女孩学习了关于事件操作和ref属性的笔记并做了表单双向绑定的练习
今天的码农女孩做了关于生命周期的笔记以及动态时钟的练习
Win10 vscode 代码格式化设置与远程断点调试
学习STM32F103时涉及的C语言知识汇总(仅链接)
Summary of Applied Cryptography
PCRE bypasses regular
判断两个时间戳是否是同一天
量化行业知识汇总
From catf1ag two-hour AK match pwn/attack killing, summarize the common command guide of emergency response
How to modify the color of a line of text in the elemtnui table (elemtnui table modifies the color of a line of text)
页面布局——三栏布局解决方式
Day10 front back continuous adjustment
XXX packages are looking for funding run `npm fund` for details解决方法
elemtnui 表格如何修改某行文字颜色(elemtnui table 修改某行文字颜色)
extern和static的区别
JS intercepts the first few digits of the string or the last few digits of the string