Base62 with Vue and axios
Encodes and decodes using external API call with Vue.js and axios()
by pleasureswx123
HTML
<script src="https://unpkg.com/[email protected]/dist/axios.min.js"></script>
<div id="app">
<p>{{ encoded }}</p>
<p>{{ decoded }}</p>
<p>{{ error }}</p>
</div>
JavaScript
/* http://base62.net/ */
var app = new Vue({
el: "#app",
data: {
encoded: "Encoding...",
decoded: "Decoding...",
error: null
},
created: function () {
var self = this;
/* axios.post('http://localhost/M-Experience/resources/GETrends.php',
{
firstName: this.name
},
{
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}); */
/* let data = JSON.stringify({
password: this.state.password,
username: this.state.email
})
axios.post('url', data, {
headers: {
'Content-Type': 'application/json',
}
}
) */
/* {
headers: { Authorization: "Bearer " + token }
} */
axios
.post("http://sso.baidu.com:8080/api/sso/logout", {data: "test data"})
.then(function (response) {
debugger;
self.encoded = response.data.encoded
})
.catch(function (error) {
self.error = "Could not reach the API: " + error
})
axios
.post("https://api.base62.io/decode", {data: "T8dgcjRGuYUueWht"})
.then(function (response) {
self.decoded = response.data.decoded
})
.catch(function (error) {
self.error = "Could not reach the API: " + error
})
}
});