Im trying to append javascript files in NUXT. but when i use nuxt.config to append javascript it works but not as I want.
head: {
title: 'mynuxt',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: 'Nuxt.js project' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
{ rel: 'stylesheet', href: 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' },
{ rel: 'stylesheet', href: '/css/bootstrap.min.css' },
{ rel: 'stylesheet', href: '/css/mdb.min.css' },
{ rel: 'stylesheet', href: '/css/style.min.css' },
],
script: [
{ src: '/js/bootstrap.min.js' },
{ src: '/js/popper.min.js' },
{ src: '/js/mdb.min.js' }
],
},
when i inspect element it inserted but in head.
Ive search already in google but did not found any solution yet. thanks in advance
js is a frontend framework built upon Vue. js that offers great development features such as server side rendering, automatically generated routes, improved meta tags managing and SEO improvement.
The static directory is directly mapped to the server root () and contains files that likely won't be changed. All included files will be automatically served by Nuxt and are accessible through your project root URL.
Next. js is basically a React framework that can be used when a user needs fast rendering in complex situations. Nuxt. js on the other hand is a Vue framework that helps in making the web development process efficient and quicker.
You have two options:
Option 1 - With guide Nuxt.js is recommended add .js
in folder plugin
https://nuxtjs.org/guide/plugins
Example:
Add new file in plugins/example.js
Then, add the file inside the plugins key of nuxt.config.js
:
module.exports = {
plugins: ['~/plugins/example']
}
Option 2 - Use in metadata with body: true
<script>
export default {
head: {
script: [
{ src: '/head.js' },
// Supported since Nuxt 1.0
{ src: '/body.js', body: true },
{ src: '/defer.js', defer: '' }
]
}
}
</script>
More info: https://github.com/nuxt/nuxt.js/issues/2000#issuecomment-341380762
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With