problem description
add a test.js, to the plugins directory as shown on the official website. I just want to hang an encapsulated websocket instance to the Vue.prototype component for direct use. Nuxt.config.js is also configured according to the documentation, but the whole test.js is not executed
the environmental background of the problems and what methods you have tried
the i18 example given on the official website is feasible, if the work in test.js is completely moved to the same js as i18, it works! It is impossible to write a test.js alone, and it will not report an error
.related codes
/ / Please paste the code text below (do not replace the code with pictures)
// plugins/test.js
import Vue from "vue"
console.log("websocket");
class WebsocketProvider {
constructor(url) {
this.url = url;
console.log(url);
this._connect();
}
_connect() {
console.log("websocket connect")
}
ping() {
console.log("pong")
}
static install(Vue, options) {
Vue.prototype.$websocket = new WebsocketProvider(123);
}
}
Vue.use(WebsocketProvider);
the above is just a simple example, in which the console.log is not executed, and neither the server nor the client
// nuxt.config.js
...
plugins: [
{src: "~/plugins/test.js", ssr: false}
],
...
what result do you expect? What is the error message actually seen?
The code intest.js can be considered completely unexecuted, there is no related error log in both the back-end console and the front-end console, and the this.$websocket in the component directly undefined, proves that it is indeed not hung. It is used completely in accordance with the official tutorials, and in order to fully comply with the standard, and even changed to the mode of Vue.use, it is done by hanging up Vue.prototype in the first place. I don"t know if this piece of
has ever been practiced.