1. Install the conversion base64 plug-in
npm install base-64 -S
2. Introduce
Node import method: var base64 = require('base-64');
Or import import import Base64 from "base-64"
3. use
let encodedData = base64.encode(String)
Convert string to base64 let decodedData = base64.decode(Base64)
Convert base64 encoding to string
The parameters received during encoding must be of string type and must be in utf-8 format. If it is not necessary to install the utf-8 plug-in to convert the data
npm install utf8 -S
Node import method: var utf8= require('utf8');
Or import import import utf8 from "utf8"
utf8.encode(string)
Convert string to utf8 format
utf8.decode(byteString)
Convert data in utf-8 format to string
or download base64-js
npm install --save js-base64
// 可直接引入使用
import { Base64 } from 'js-base64';
const base64 = Base64.encode(JSON.stringify(Object/Array)) // 解析为Base64字符
const json = Base64.decode(base64) // Base64字符转为json数据
// 或挂载在原型对象上使用
Vue.prototype.$base = require('js-base64').Base64 //全局引用base64
let base64 = this.$base.encode(JSON.stringify(Object/Array));
let json = this.$base.decode(base64);