欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue?路由傳參加密的示例代碼

 更新時間:2022年12月12日 17:11:22   作者:左手倒影ZY  
這篇文章主要介紹了Vue?路由傳參加密,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

Vue 路由傳參加密

首先,創(chuàng)建一個base64.js

const Base64 = {
   //加密
    encode(str) {
        return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
            function toSolidBytes(match, p1) {
                return String.fromCharCode('0x' + p1);
            }));
    },
  //解密
    decode(str) {
        // Going backwards: from bytestream, to percent-encoding, to original string.
        return decodeURIComponent(atob(str).split('').map(function (c) {
            return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
        }).join(''));
    }
}
export default Base64

在main.js里面引用

import Base64 from './assets/js/base64.js' 

Vue.prototype.$Base64 = Base64;

使用頁面:

this.$router.push({
  path: "/user/Recommend",
  query:{
    info:this.$Base64.encode(XXXXX)//this.$Base64.encode(JSON.stringify(row))
  }
});

接受參數(shù)頁面:

let params = JSON.parse(this.$Base64.decode(this.$route.query.info))

Vue項目:路由跳轉(zhuǎn)時中文傳參被URL編碼,怎么解決?用js封裝Base64編碼解碼加密解密

1.在utils中封裝js方法,代碼如下:

var Base64 = {
?
    // private property
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", //密鑰(不能修改)
    
    // public method for encoding
    encode: function(input) {
    var output = "";
    var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
    var i = 0;
    
    input = Base64._utf8_encode(input);
    
    while (i < input.length) {
    
    chr1 = input.charCodeAt(i++);
    chr2 = input.charCodeAt(i++);
    chr3 = input.charCodeAt(i++);
    
    enc1 = chr1 >> 2;
    enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
    enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
    enc4 = chr3 & 63;
    
    if (isNaN(chr2)) {
    enc3 = enc4 = 64;
    } else if (isNaN(chr3)) {
    enc4 = 64;
    }
    
    output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
    
    }
    
    return output;
    },
    
    // public method for decoding
    decode: function(input) {
    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;
    
    input = input.replace(/[^A-Za-z0-9+/=]/g, "");
    
    while (i < input.length) {
    
    enc1 = this._keyStr.indexOf(input.charAt(i++));
    enc2 = this._keyStr.indexOf(input.charAt(i++));
    enc3 = this._keyStr.indexOf(input.charAt(i++));
    enc4 = this._keyStr.indexOf(input.charAt(i++));
    
    chr1 = (enc1 << 2) | (enc2 >> 4);
    chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
    chr3 = ((enc3 & 3) << 6) | enc4;
    
    output = output + String.fromCharCode(chr1);
    
    if (enc3 != 64) {
    output = output + String.fromCharCode(chr2);
    }
    if (enc4 != 64) {
    output = output + String.fromCharCode(chr3);
    }
    
    }
    
    output = Base64._utf8_decode(output);
    
    return output;
    
    },
    
    // private method for UTF-8 encoding
    _utf8_encode: function(string) {
    string = string.replace(/ /g, " ");
    var utftext = "";
    
    for (var n = 0; n < string.length; n++) {
    
    var c = string.charCodeAt(n);
    
    if (c < 128) {
    utftext += String.fromCharCode(c);
    } else if ((c > 127) && (c < 2048)) {
    utftext += String.fromCharCode((c >> 6) | 192);
    utftext += String.fromCharCode((c & 63) | 128);
    } else {
    utftext += String.fromCharCode((c >> 12) | 224);
    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
    utftext += String.fromCharCode((c & 63) | 128);
    }
    
    }
    
    return utftext;
    },
    
    // private method for UTF-8 decoding
    _utf8_decode: function(utftext) {
    var string = "";
    var i = 0;
    var c,c1,c2,c3 = 0;
    
    while (i < utftext.length) {
    
    c = utftext.charCodeAt(i);
    
    if (c < 128) {
    string += String.fromCharCode(c);
    i++;
    } else if ((c > 191) && (c < 224)) {
    c2 = utftext.charCodeAt(i + 1);
    string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
    i += 2;
    } else {
    c2 = utftext.charCodeAt(i + 1);
    c3 = utftext.charCodeAt(i + 2);
    string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
    i += 3;
    }
    
    }
    
    return string;
    }
    
    }
?
    export default Base64

2.在main.js中引入并掛載到vue原型對象上

//Base64加密
import Base64 from '@/utils/base64.js'
Vue.prototype.$Base64 = Base64

3.在vue文件中使用

this.$Base64.encode(str) //加密
this.$Base64.decode(str) //解密

拓展:編碼解碼的其他方式

1.md5

常用于加密,可以暴力反向破解但是難度很大,一般來說,對md5加密的要求是現(xiàn)代算力最高的計算機需要花百年才能進(jìn)行解密

2.window對象自帶的編碼解碼

window.btoa(str) //對str進(jìn)行編碼

binary to ascii,用于將ascii字符串二進(jìn)制數(shù)據(jù)轉(zhuǎn)換成一個base64編碼過的字符串表示,即Base64的編碼過程,常用于編碼字符串。btoa不能編輯Unicode字符

window.atob(str) //對str進(jìn)行解碼

ascii to binary,用于解碼一個已經(jīng)被base-64編碼過的數(shù)據(jù),即解碼Base64編碼的字符串。

3.Unicode字符編碼

encodeURI(str) //將URL地址編碼轉(zhuǎn)變成ASCII字符序列
decodeURI(str) //將ASCII字符序列解碼轉(zhuǎn)變成UTL地址
encodeURIComponent(str) //將中文字符編碼轉(zhuǎn)變成ASCII字符序列
decodeURIComponent(str) //將ASCII字符序列解碼轉(zhuǎn)變成中文字符

4.使用JS函數(shù)的escape()和unescape()

var escape1 =escape("我的名字是:");//編碼
      console.log(escape1);
      var unescape1 = unescape(escape1); //解碼
      console.log(unescape1);

到此這篇關(guān)于Vue 路由傳參加密的文章就介紹到這了,更多相關(guān)Vue 路由傳參加密內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue+Element-ui日歷排班自定義實例代碼

    Vue+Element-ui日歷排班自定義實例代碼

    這篇文章主要給大家介紹了關(guān)于Vue+Element-ui日歷排班自定義的相關(guān)資料,有現(xiàn)成的日歷插件但是不符合需求,所以項目中使用vue+element的表格組件自己實現(xiàn)一個日歷組件,需要的朋友可以參考下
    2023-09-09
  • Vue引入jquery實現(xiàn)平滑滾動到指定位置

    Vue引入jquery實現(xiàn)平滑滾動到指定位置

    這篇文章主要介紹了Vue引入jquery實現(xiàn)平滑滾動到指定位置的效果,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧
    2018-05-05
  • Ant Design Vue日期組件的時間限制方式

    Ant Design Vue日期組件的時間限制方式

    這篇文章主要介紹了Ant Design Vue日期組件的時間限制方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • Vue3之Mixin的使用方式(全局,局部,setup內(nèi)部使用)

    Vue3之Mixin的使用方式(全局,局部,setup內(nèi)部使用)

    這篇文章主要介紹了Vue3之Mixin的使用方式(全局,局部,setup內(nèi)部使用),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • axios+Vue實現(xiàn)上傳文件顯示進(jìn)度功能

    axios+Vue實現(xiàn)上傳文件顯示進(jìn)度功能

    這篇文章主要介紹了axios+Vue上傳文件顯示進(jìn)度效果,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-04-04
  • 詳解Vue.js之視圖和數(shù)據(jù)的雙向綁定(v-model)

    詳解Vue.js之視圖和數(shù)據(jù)的雙向綁定(v-model)

    本篇文章主要介紹了Vue.js之視圖和數(shù)據(jù)的雙向綁定(v-model),使用v-model指令,使得視圖和數(shù)據(jù)實現(xiàn)雙向綁定,有興趣的可以了解一下
    2017-06-06
  • vue2.0 下拉框默認(rèn)標(biāo)題設(shè)置方法

    vue2.0 下拉框默認(rèn)標(biāo)題設(shè)置方法

    今天小編就為大家分享一篇vue2.0 下拉框默認(rèn)標(biāo)題設(shè)置方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • Vuex中Store的簡單實現(xiàn)

    Vuex中Store的簡單實現(xiàn)

    這篇文章主要介紹了Vuex中Store的簡單實現(xiàn),為了在 Vue 組件中訪問 this.$store property,你需要為 Vue 實例提供創(chuàng)建好的 store,Vuex 提供了一個從根組件向所有子組件,以 store 選項的方式 注入 該 store 的機制,需要的朋友可以參考下
    2023-11-11
  • react里組件通信的幾種方式小結(jié)

    react里組件通信的幾種方式小結(jié)

    本文主要介紹了react里組件通信的幾種方式小結(jié),包含了5種方式,主要是props傳遞,回調(diào)函數(shù)作為props,Context,Redux或MobX,refs,具有一定的參考價值,感興趣的可以了解一下
    2024-06-06
  • vue3組合式API獲取子組件屬性和方法的代碼實例

    vue3組合式API獲取子組件屬性和方法的代碼實例

    這篇文章主要為大家詳細(xì)介紹了vue3組合式API獲取子組件屬性和方法的代碼實例,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-01-01

最新評論