Home > Web Front-end > JS Tutorial > body text

Detailed explanation of the steps for setting global styles in Vue2.0

php中世界最好的语言
Release: 2018-04-14 15:24:17
Original
2522 people have browsed it

This time I will bring you a detailed step-by-step explanation of setting global styles in Vue2.0. What are the precautions? The following is a practical case. One Get up and take a look.

Setting global styles for Vue requires several steps (if it is sass, just change less to sass)

Step one: Add the following code to main.js in the src directory, which is the entry file

require('!style-loader!css-loader!less-loader!./common/less/index.less')
Copy after login

This can be written in Vue version 1.0, but not in version 2.0. An error will be reported and a parsing error will be reported

require('./common/less/index.less')
Copy after login

Second step: In the webpack.base.conf.js configuration module in the build directory, you only need to add two modules under rules

module.exports = {
 module: {
 rules: [
  {
  test: /\.less$/,
  loader: 'style-loader!css-loader!less-loader'
  },
  {
  test:/\.css$/,
  loader:'css-loader!style-loader',
  }
 ] 
 }  
}
Copy after login

Step 3: If an error is reported, you may not install the above dependencies. You need to add dependencies in the package.json file in the root directory

Detailed explanation of the steps for setting global styles in Vue2.0

Step 4:Execute the command in the command window to install dependencies

npm install
Copy after login

Linux (ubuntu, deepin), Mac os system may prompt that the permissions are insufficient and need to obtain permissions, then you only need to obtain permissions in front

sudu npm install
Copy after login

If you need to use less later, just add the lang attribute to the style

<style></style>
Copy after login

If there are many public files, you can put them all in one file and implement global styles of multiple style files through public file links.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website !

Recommended reading:

How element-ui implements the reuse of Table components

detailed explanation of the scope usage of js

Detailed explanation of the steps for setting global styles in Vue2.0JS canvas makes rotation animation

The above is the detailed content of Detailed explanation of the steps for setting global styles in Vue2.0. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!