学习vue的第一天

一.下载相关node,vscode,配置环境

二.打开cmd,输入npm create vite@lastest,搭建vue+vite项目

三.找到App.vue,可以将其理解成java中的主线程main,在components文件中下面使用组件(创建.vue文件),其中所用的vue文件的格式如下

<template>

 </template>

<script setup>

</script>

<style scoped>

</style>

在App.vue在script中建立import引用components文件中的组件,在template中使用相应的引用举例如下

<script setup>

import First from './components/First.vue',

</script>

<template>

  <First />

</template>

四.接下来,重点是学习组件

1.template中写html script中写js style中写css

js中写变量,对应的在html中发挥作用如

<template>

   <div>{{ msg }}</div>

</template>

<script setup>

let msg = '你好,李焕英'

</script>

页面会动态显示:你好,李焕英

2.响应式-ref

(1)<template>

    <button @click="count++">

{{ count }}

</button>

</template>

<script setup>

import { ref } from 'vue'

let count = ref(0)

</script>

<style scoped>

</style>

简单使用ref

(2)<template>

    <button @click="shu">

{{ count }}

</button>

</template>

<script setup>

import { ref } from 'vue'

let count = ref(0)

function shu(){

    count.value++

    console.log(document.querySelector('button').innerText)

}

</script>

<style scoped>

</style>

通过函数使用ref

(3)<template>

    <button @click="shu">

{{ count }}

</button>

</template>

<script setup>

import { nextTick, ref } from 'vue'

let count = ref(0)

async function shu(){

    count.value++

    await nextTick()

    console.log(document.querySelector('button').innerText)

}

</script>

<style scoped>

</style>

使用异步方法nextTick完成异步操作是的操作台上面数据和点击产生的数据一致

3.响应式-和ref对比reactive只能运用到引用类型中

4.计算属性 计算属性缓存 vs 方法 计算属性可以缓存没有必要重复调用,而方法则不行

5.class与style绑定

6.条件渲染v-if 指令用于条件性地渲染一块内容。这块内容只会在指令的表达式返回真值时才被渲染。你也可以使用 v-else 为 v-if 添加一个“else 区块”。

7.列表渲染v—for

8.事件监听

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值