preface
qrcodejs2.js/QRCode.js
plug-in is in normalVue.js
project works normally. When you are innuxt.js
when used in the project, there will be an error, becauseqrcodejs2.js/qrcode.js
the plug-in internally uses “browser specific (such as window/document) objects”. When compiled intonuxt.js
without these, an error will be generated.
This article will provide you with the way to introduce the plug-in from 0-1, which runs perfectly.
Qrcodejs2.js and QRcode JS can be used.
First step
Download the adapter
nuxt.js
plug-in core code online.
Step 2
Prepare the file you just downloaded.
Put the QRcode.min.js
file into the JS
folder under the static static
directory of the project (create one if you don’t have one).
Step 3
This step requires you to read the notes carefully, and you must understand why the path is written in this way.
Open the project nuxt.config.js
configuration file, add the following code to the head
configuration item:
// For now, we are using the local IP address http://192.168.3.5:8001 because we are in a development environment.
// Please replace it when you deploy your project later.
// --------- ---------- ---------- ---------- ---------
// For example, my future website deployment will be: http://www.demo.com
// Then this is how it should be written: http://www.demo.com/js/qrcode.min.js
// [domain + /js/qrcode.min.js]
src: 'http://192.168.3.5:8001/js/qrcode.min.js'
As shown in the following figure, pay attention to the position:
Step 4
At this point, your project can use the plug-in.
Cancel your import
Import Code:
Test use
Or the original way of use:
// QRCode The keyword is a wrapped instance of the plugin, you can't change it!
let qrcode = new QRCode(qrcodeImgEl, {
width: 100,
height: 100,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H
})
Read More:
- [Solved] Vuepress Package Error: document is not defined
- [Solved] NUXT.JS. npm run dev Error: Error: error:0308010C:digital envelope routines::unsupported
- Vue JS import font.css error [How to Solve]
- [Solved] webpack Package Error: ERROR in multi ./src/main.js ./dist/bundle.js Module not found: Error: Can‘t resolv
- [vite] Failed to parse source for import analysis because the content contains invalid JS syntax.
- js: SyntaxError: Cannot use import statement outside a module
- [Solved] mqtt.js Error: n.createConnection is not a function
- Solution to some map files in JS folder after Vue packaging (remove the map. JS file)
- Vue Import three.JS error: Unexpected token [How to Solve]
- Solution to build error in Vue project (error in static/JS)/vendor.xxxxx.js from UglifyJs)
- [Solved] Failed to load plugin ‘vue‘ declared in ‘.eslintrc.js‘: createRequire is not a function
- vue.config.js build Package UglifyJsPlugin to clear console and print console.log Error: `warnings` is not a supported option
- Module not found: Error: Can‘t resolve ‘core-js/modules/es.promise.js‘ in
- [Solved] The code checked with flow.js does not report an error
- [Solved] node.js Upload Files Error: Multipart: boundary not found multer
- [Solved] Vue 3 Script Setup ESLint Error: ‘defineProps‘ is not defined
- [Solved] This dependency was not found: * core-js/modules/es.error.cause.js in ./node_modules/_@babel_runtim
- [Solved] react-router-dom Error: index.js:1 Warning: Functions are not valid as a React child.
- JS async await Error: Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
- How to Solve “Vue is not defined” Error