[转] VUE 组件的构成

一个基本的 vue 组件结构类似这样:

<template>
  <h1>这是 App.vue 根组件</h1>
  <h3>abc -- {{username}}</h3>

  <hr />
  <p>count 值是:{{ count }}</p>
  <button @click="count++">+1</button>
  <button @click="addCount">+2</button>
</template>

<script>
export default {
  name: 'MyApp',
  data(){
    return {
      username: 'zs',
      count: 0
    }
  },
  methods:{
    addCount(){
      this.count += 2
    }
  }
} 
</script>

<style lang="css">
  h1{
    color:#f00;
  }
</style>

默认情况下, style 支持的是 css ,如果希望使用 less 语法,可以按以下步骤进行配置:

1、安装依赖包,提供编译支持

cnpm install less -D

2、在 style 标签上添加 lang="less" 属性

<style lang="less">
  h1{
    color:#f00;
  }
</style>

 

 

posted on 2022-10-24 19:03  z5337  阅读(48)  评论(0)    收藏  举报