Home > Web Front-end > Vue.js > body text

How to add css styles to components in vue

coldplay.xixi
Release: 2023-01-13 00:44:50
Original
5106 people have browsed it

How vue adds CSS styles to components: First set the relevant code in the [.vue] file; then create a new [index.js] file and create the corresponding [record.scss] file.

How to add css styles to components in vue

The operating environment of this tutorial: Windows 7 system, Vue version 2.9.6, Dell G3 computer.

【Recommended related articles: vue.js

Vue’s method of adding CSS styles to components:

First, set the following settings in the .vue file:

<template src="./record.html"></template>
<script src="./record.js"></script>
<style src="./record.scss"></style>
Copy after login

Create a new index.js file as follows:

import record from &#39;./record.vue&#39;;
export default record;
Copy after login

Create the corresponding record.html and record.js , record.scss file, take .js as an example:

// -- NAME --
const name = &#39;record&#39;;
// -- DATA --
const data = function () {
  return {
    
  };
};
// -- COMPUTED --
const computed = {
 
};
// -- COMPONENTS -- 
const components = {
}
// -- WATCH --
const watch = {
  
};
// -- METHODS --
const methods = { 
  
};
// -- HOOKS --
function mounted() {
}
// == EXPORT ==
export default {
  name: name,
  data: data,
  components: components,
  computed: computed,
  watch: watch,
  methods: methods,
  mounted: mounted
};
Copy after login

Another method can be quoted directly:

<template>
  <div>html</div>
</template>
<script src="./***.js"></script>
<style src="./***.css"></style>
Copy after login

There are various forms, but the basic idea is to separate independent files , introduce loading

Related free learning recommendations: javascript (video)

The above is the detailed content of How to add css styles to components in vue. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
vue
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