qs的使用

qs是一個url參數轉化(parse和stringify)的js庫
用法:

<template>
    <div>
        qs.js
    </div>
</template>

<script>
    import qs from 'qs'
    import _ from 'lodash'
    export default {
        components: {},
        methods: {
            qs() {
                var obj = qs.parse('a=b&c=d');
                //輸出true
                console.log(_.isEqual(obj, {
                    a: 'b',
                    c: 'd'
                }))

                var str = qs.stringify(obj);
                //輸出true
                console.log(_.isEqual(str, 'a=b&c=d'));
            }
        },
        mounted() {
            this.qs();
        }
    };
</script>

<style scoped>

</style>

stringfy方法:

<template>
    <div>
        qs.js
    </div>
</template>

<script>
    import qs from 'qs'
    import _ from 'lodash'
    export default {
        components: {},
        methods: {
            qs() {
                var obj = qs.parse('a=b&c=d');
                //輸出true
                console.log(_.isEqual(obj, {
                    a: 'b',
                    c: 'd'
                }))

                var str = qs.stringify(obj);
                //輸出true
                console.log(_.isEqual(str, 'a=b&c=d'));
            }
        },
        mounted() {
            this.qs();
        }
    };
</script>

<style scoped>

</style>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章