I'm new to vue js and trying to learn this. I installed a fresh new version of vue webpack in my system. I'm having a css, js and images of this a theme template which I want to include into the HTML so i tried adding it in index.html
but I can see errors in console and the assets are not being added. While I searched I came to know that I can use require
in main.js
file. But I'm getting the error:
Following I've tried in my main.js
file:
// The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from 'vue' import App from './App' import router from './router' require('./assets/styles/vendor.css'); require('./assets/styles/main.css'); require('./assets/scripts/vendor/modernizr.js'); Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ el: '#app', router, template: '<App/>', components: { App } })
While I tried using import to use it but still I got error
// The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from 'vue' import App from './App' import router from './router' import('./assets/styles/vendor.css') // require('./assets/styles/vendor.css'); // require('./assets/styles/main.css'); // require('./assets/scripts/vendor/modernizr.js'); Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ el: '#app', router, template: '<App/>', components: { App } })
Here is the error screenshot:
Help me out in this.
In Vue. js, we can add an inline style to our element by binding the style attribute in the HTML tag. For reference, :style is shorthand for v-bind:style . Inline styling can be done in two ways: using object syntax or array syntax.
STEP 01: First, Import the Child Component into the Parent Component inside script tag but above export default function declaration. STEP 02: Then, Register the Child Component inside the Parent Component by adding it to components object. STEP 03: Finally, Use the Child Component in the Parent Component Template.
Importing CSS in Vue components If you are setup and using webpack, you should be able to import css directly from inside <style> tags in component files. More info here: https://cli.vuejs.org/guide/css.html.
To add global CSS in Vue. js, we can import our global CSS file in main. js . import "./assets/css/main.
You can import the css file on App.vue, inside the style tag.
<style> @import './assets/styles/yourstyles.css'; </style>
Also, make sure you have the right loaders installed, if you need any.
Try using the @
symbol before the url string. Import your css in the following manner:
import Vue from 'vue' require('@/assets/styles/main.css')
In your App.vue file you can do this to import a css file in the style tag
<template> <div> </div> </template> <style scoped src="@/assets/styles/mystyles.css"> </style>
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