uniapp常用标签

一.uni-app常用标签

该组件类似HTML中的<a>组件,但只能跳转本地页面。目标页面必须在pages.json中注册
二. 标签用法
1.view
类似于HTML中的div标签通常用于布局和包裹其他标签


2.scroll-view
在指定的区域设置一块可以左右滚动的区域,通常用于下拉刷新和商品主体部分


代码示例
<template>
    <scroll-view class="scrollview" scroll-y="true">
        <view class="box">0</view>
        <view class="box">1</view>
        <view class="box">2</view>
        <view class="box">3</view>
        <view class="box">4</view>
        <view class="box">5</view>
        <view class="box">6</view>
        <view class="box">7</view>
        <view class="box">8</view>
        <view class="box">9</view>
    </scroll-view>
</template>
 
<script>
 
</script>
 
<style>
    .scrollview {
        height: 100px;
        border: 1px solid red;
        white-space: nowrap;
    }
 
    .box {
        widows: 100px;
        height: 100px;
        background-color: aqua;
 
    }
</style>

3.swiper
用于制作轮播图


代码示例
<template>
<swiper class="swiper" indicator-dots autoplay interval="1000">
    <swiper-item class="swiperview">111</swiper-item>
    <swiper-item class="swiperview">222</swiper-item>
    <swiper-item class="swiperview">333</swiper-item>
    <swiper-item class="swiperview">444</swiper-item>
    </swiper>
</template>
 
<script>
 
</script>
 
<style>
    .swiper {
        height: 100px;
        border: 1px solid red;
        white-space: nowrap;
    }
 
    .swiperview {
        widows: 100px;
        height: 100px;
        background-color: aqua;
 
    }
</style>

4.image
相对于HMTL中的img,用于展示图片


代码示例
<template>
    <scroll-view class="scrollview" scroll-y="true">
        <image src="../../static/1.jpeg" class="imger"></image>
        <image src="../../static/2.jpeg" class="imger"></image>
        <image src="../../static/3.png" class="imger"></image>
        <image src="../../static/4.jpg" class="imger"></image>
        <image src="../../static/5.png" class="imger"></image>
    </scroll-view>
</template>
 
<script>
 
</script>
 
<style>
    .scrollview {
        height: 280px;
        border: 1px solid red;
    }
</style>

5.text

6.navigator


7.button

### UniApp 标签使用教程 #### 一、标签概述 UniApp 提供了一套丰富的内置标签,这些标签可以用于构建跨平台的应用程序。通过合理运用这些标签,开发者能够快速搭建出功能强大的应用界面[^1]。 #### 二、常用标签介绍 ##### 1. view 组件 `<view>` 是最常用的布局容器之一,在页面中起到承载其他子元素的作用。 ```html <template> <view class="container"> <!-- 子组件 --> </view> </template> <style scoped lang="scss"> .container { padding: 20px; } </style> ``` ##### 2. text 组件 `<text>` 主要用来显示纯文本内容,支持简单的富文本格式化。 ```html <template> <text selectable>{{ message }}</text> </template> <script setup> import { ref } from 'vue'; const message = ref('Hello, world!'); </script> ``` ##### 3. button 组件 按钮是交互设计中的重要组成部分,`<button>` 可以轻松创建各种类型的点击事件触发器。 ```html <template> <button type="primary" @click="handleClick">点击这里</button> </template> <script setup> function handleClick() { console.log('Button clicked'); } </script> ``` ##### 4. image 组件 图片展示必不可少,`<image>` 支持本地资源以及网络路径加载图像素材。 ```html <template> <image src="/static/logo.png"></image> </template> ``` #### 三、高级特性——条件渲染与列表循环 除了基本的静态结构外,还可以利用 v-if/v-for 指令实现动态效果: - **v-if**: 控制元素是否呈现给用户; - **v-for**: 遍历数组或对象来生成重复性的UI片段; 示例代码如下所示: ```html <template> <block v-if="isVisible"> <text>这段文字只有当 isVisible 为 true 才会显示。</text> </block> <ul> <li v-for="(item,index) in items" :key="index">{{ item.name }}</li> </ul> </template> <script setup> import { reactive, toRefs } from 'vue'; let state = reactive({ isVisible: false, items:[ {"name":"苹果"}, {"name":"香蕉"} ] }); // 解构赋值并暴露出去 const { isVisible,items }=toRefs(state); </script> ``` #### 四、样式处理方式 为了更好地管理样式表单,推荐采用 SCSS 或者 Less 等预处理器语法编写 CSS 文件,并将其引入到项目当中[^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

magic33416563

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值