


Two ways for Vue single-page application to reference separate style files
This article will introduce to you how to reference a separate style file in a Vue single-page application. This article takes the css file as an example and introduces it to you in two ways in great detail. Friends who need it can refer to it
Problem description
For .vue files, they are also composed of three parts: structure, behavior, and style. There is a scoped attribute in the style part, that is The current page is valid. When there are many styles in the style tag or there are duplications between .vue files, it always feels that it does not look neat enough, so you need to introduce some common styles. Let’s first talk about how to introduce separate style files. Here we take CSS files as an example, and then talk about the division of style files in my project
Introducing separate style files
Method 1
Introduce static resources into main.js. This method makes the style file shared by components in the project
// 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 ElementUI from 'element-ui' import 'element-ui/lib/theme-chalk/index.css' import axios from 'axios' // 此处引入静态资源 require('./assets/css/style.css') /* eslint-disable no-new */ new Vue({ el: '#app', router, template: '<App/>', components: { App } })
Method 2
Introduce style files into a certain .vue
<template> ... </template> <script> export default { name: "test" } </script> <style scoped> @import "style.css"; </style>
The file organization format is as follows:
Applications in the project
In my project, both methods are applied. The public styles are referenced in the first method, and the styles of each module in the project are referenced in the second method. In each module, It contains a style file, which is used to store the styles needed in this module. At this time, you need to be more flexible. If there are relatively few styles, or only a certain vue file will use it, you can still write the css style directly in the .vue file. in the style tag.
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Implementation of vue’s keep-alive cache function
Collect url and href of front-end interview questions , src
The above is the detailed content of Two ways for Vue single-page application to reference separate style files. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In macOS Sonoma, widgets don't have to be hidden off-screen or forgotten in the Notification Center panel like they did in previous versions of Apple's macOS. Instead, they can be placed directly on your Mac’s desktop – they’re also interactive. When not in use, macOS desktop widgets fade into the background in a monochrome style, reducing distractions and allowing you to focus on the task at hand in the active application or window. However, when you click on the desktop, they return to full color. If you prefer a drab look and want to retain that aspect of uniformity on your desktop, there's a way to make it permanent. The following steps demonstrate how it is done. Open the System Settings app

In iOS 17 and macOS Sonoma, Apple has added new formatting options for Apple Notes, including block quotes and a new Monostyle style. Here's how to use them. With additional formatting options in Apple Notes, you can now add block quotes to your notes. The block quote format makes it easy to visually offset sections of writing using the quote bar to the left of the text. Just tap/click the "Aa" format button and select the block quote option before typing or when you are on the line you want to convert to a block quote. This option applies to all text types, style options, and lists, including checklists. In the same Format menu you can find the new Single Style option. This is a revision of the previous "equal-width"

C++ is a popular programming language, but during use, the compilation error "undefined reference" often occurs, which brings a lot of trouble to program development. This article will discuss the solution to the "undefined reference" error from both the cause and the solution. 1. Cause of error When the C++ compiler compiles a source file, it will be divided into two stages: the compilation stage and the link stage. The compilation phase converts the source code in the source files into assembly code, while the linking phase combines different source files into an executable file.

Guide to solving misaligned WordPress web pages In WordPress website development, sometimes we encounter web page elements that are misaligned. This may be due to screen sizes on different devices, browser compatibility, or improper CSS style settings. To solve this misalignment, we need to carefully analyze the problem, find possible causes, and debug and repair it step by step. This article will share some common WordPress web page misalignment problems and corresponding solutions, and provide specific code examples to help develop

The benefits of functions returning reference types in C++ include: Performance improvements: Passing by reference avoids object copying, thus saving memory and time. Direct modification: The caller can directly modify the returned reference object without reassigning it. Code simplicity: Passing by reference simplifies the code and requires no additional assignment operations.

CSS web page background image design: Create various background image styles and effects, specific code examples are required Summary: In web design, background images are an important visual element, which can effectively enhance the attractiveness and readability of the page. This article will introduce some common CSS background image design styles and effects, and provide corresponding code examples. Readers can select and apply these background image styles and effects according to their own needs and preferences to achieve better visual effects and user experience. Keywords: CSS, background image, design style, effect, code representation

References and pointers in C++ are both methods of passing function parameters, but there are differences. A reference is an alias for a variable. Modifying the reference will modify the original variable, while the pointer stores the address of the variable. Modifying the pointer value will not modify the original variable. When choosing to use a reference or a pointer, you need to consider factors such as whether the original variable needs to be modified, whether a null value needs to be passed, and performance considerations.

By using pointers and references, memory usage in C++ can be optimized: Pointers: store addresses of other variables and can point to different variables, saving memory, but may generate wild pointers. Reference: Aliased to another variable, always points to the same variable, does not generate wild pointers, and is suitable for function parameters. Optimizing memory usage can improve code efficiency and performance by avoiding unnecessary copies, reducing memory allocations, and saving space.
