Answer the question
In order to leave comments, you need to log in
Nodejs native in vue, how to make https a plugin?
Plan to use native Nodejs requests in Vue
Stack:
electron-vue
vue
require("follow-redirects").https
var https = require('follow-redirects').https;
var fs = require('fs');
var options = {
'method': 'GET',
'hostname': 'example.com',
'path': 'example.com',
'headers': {
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
req.end();
"use strict"
import Vue from "vue"
const _https = require("follow-redirects").https;
Plugin.install = function (Vue) {
Vue.https = _https
window.https = _https
Object.defineProperties(Vue.prototype, {
https: {
get () {
return _https
}
},
$https: {
get () {
return _https
}
}
})
}
Vue.use(https)
export default Plugin
Answer the question
In order to leave comments, you need to log in
The problem is a name conflict.
Here is a working version.
Easier nowhere.
const { http, https } = require("follow-redirects")
const HttpsPlugin = {
install: function(Vue, options) {
Vue.https = https
window.https = https
Object.defineProperties(Vue.prototype, {
https: {
get() {
return https
}
},
$https: {
get() {
return https
}
},
})
}
}
Vue.use(HttpsPlugin)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question