今天根据老师视频学习了几个vue的功能
<template>
<view>
<image :src="pic" mode="widthFix" class="pic4">image>
<button type="primary" :loading="isActive ? true : false">按钮button>
view>
<view class="box" :class="{activie:isActive}">v-bind指令view>
<view class="box" :class="isActive ? 'activie' : '' ">v-bind指令2view>
<view class="box" :style="{width: '300px',height:260+'px',fontSize:size+'px'}">内联样式view>
template>
<script setup>
import {
ref
} from 'vue';
const arry = ref([
"../../static/pic1.png",
"../../static/pic2.png",
"../../static/pic3.webp",
"../../static/pic4.jpg"
])
const pic = ref("../../static/pic1.png")
let isActive = ref(false);
const size = ref(30);
let i = 0;
setInterval(() => {
i++;
// size.value+=i;
pic.value = arry.value[i % 4]
isActive.value = !isActive.value;
}, 5000)
script>
<style lang="scss" scoped>
.pic4 {
width: 100vw;
height: 200px;
}
.box {
width: 200px;
height: 200px;
background: red;
font-size: 20px;
margin: 5px; //这是当前组件距离边框的距离
padding: 10px; //这是文字的边距
}
.activie {
background: yellow;
color: #0055ff;
}
style>
<template>
<view class="box" @click="onChick" :style="{background:colo}">
{{num}}
view>
<switch :checked="isChecked" @change="onchange"/>
<button type="primary" :loading="isChecked">按钮button>
<switch checked="true" @change="onChange" />
template>
<script setup>
import { ref } from 'vue';
const num=ref(0);
const colo=ref("#00aaff")
const isLoading=ref(false);
const isChecked=ref(true);
function onChick(){
num.value++
colo.value="#"+String(Math.random()).substr(3,6);
console.log(Math.random());
console.log(String(Math.random()).substr(3,6));
}
function onchange(e){
isLoading.value=e.detail.value;
console.log(1+"/"+e.detail.value);
}
function onChange(e){
isChecked.value=e.detail.value;
console.log(2+"/"+e.detail.value);
}
script>
<style lang="scss" scoped>
.box{
width: 100px;
height: 100px;
}
style>
<template>
<view>
<view v-if="vIf">京东view>
<view v-else>淘宝view>
<view v-if="week===1">星期一view>
<view v-else-if="week===2">星期二view>
<view v-else-if="week===3">星期三view>
<view v-else-if="week==4">星期四view>
<view v-else-if="week==5">星期五view>
<view v-else-if="week==6">星期六view>
<view v-else-if="week==0">星期日view>
-------------
<text>
\n 在uniapp中,== 和 === 是两个不同的运算符,它们在比较时有所不同:\n
== 是相等运算符,它在比较时会进行类型转换(强制类型转换),如果两个值相等则返回 true,否则返回 false。\n
=== 是严格相等运算符,它在比较时不会进行类型转换,如果两个值的类型不同,则直接返回 false;只有当两个值的类型相同时,它才会比较值本身是否相等。
text>
view>
template>
<script setup>
import {
ref
} from 'vue';
const vIf = ref(false)
let week=new Date().getDay(); //这是获取当前是星期几的代码
script>
<style lang="scss" scoped>
style>