uniapp中使用uni-ui组件库

  1. src目录下新建components目录
  2. 从uni-ui引入对应的组件目录,如下图
  3. 直接使用组件,demo
javascript 复制代码
<template>
    <view id="my" data-name="王五" data-age="18">my页面</view>

    <uni-data-select 
    :localdata="localdata"
    :value="valueGender"
    clear
    placeholder="请选择性别"
    @change="handleChangeGender"
    />

    <uni-datetime-picker />

    <uni-form>
        <uni-form-item label="姓名">
            <input v-model="name" type="text" placeholder="请输入姓名" />
        </uni-form-item>
        <uni-form-item label="年龄">
            <input type="number" v-model="age" placeholder="请输入年龄" />
        </uni-form-item>
        <uni-form-item label="性别">
            <radio-group :value="gender" @change="handleGender">
                <radio value="11">男</radio>
                <radio value="22">女</radio>
                <radio value="33">未知</radio>
            </radio-group>
        </uni-form-item>
        <uni-form-item label="爱好">
            <checkbox-group :value="hobbies" @change="handleHobbies">
                <checkbox value="11">篮球</checkbox>
                <checkbox value="22">足球</checkbox>
                <checkbox value="33">乒乓球</checkbox>
            </checkbox-group>
        </uni-form-item>
        <uni-form-item label="城市">
            <uni-data-select 
                :localdata="localdataCity"
                :value="valueCity"
                clear
                placeholder="请选择城市"
                @change="handleChangeCity"
            />
        </uni-form-item>
        <uni-form-item label="日期">
            <uni-datetime-picker v-model="date" type="date" />
        </uni-form-item>
        <uni-form-item label="时间">
            <uni-datetime-picker v-model="time" type="time" />
        </uni-form-item>
        <uni-form-item label="滑块">
            <slider value="0" @change="sliderChange" show-value />
        </uni-form-item>
        <uni-form-item label="开关">
            <switch @change="handleSwitch" />
        </uni-form-item>
        <uni-form-item label="文本域">
            <textarea v-model="textarea" placeholder="请输入文本" />
        </uni-form-item>
        <uni-form-item label="图片">
            <image src="/static/logo.png" />
        </uni-form-item>
        <uni-form-item label="视频">
            <audio src="/static/mp-weixin/qq提示音.mp3" controls />
        </uni-form-item>

        <uni-form-item>
            <button type="primary" @click="handleClick">提交</button>
        </uni-form-item>
    </uni-form>
</template>

<script>
export default{
    data() {
        return {
            localdata: [
                {text: "男", value: 11},
                {text: "女", value: 22},
                {text: "未知", value: 33},
            ],
            valueGender: "",
            name: "",
            age: "",
            gender: "",
            hobbies: [],
            localdataCity: [
                {text: "北京", value: 11},
                {text: "上海", value: 22},
                {text: "广州", value: 33},
            ],
            valueCity: "",
            date: "",
            time: "",
            sliderValue: 0,
            checked: false,
            textarea: ""
        }
    },
    onLoad() {
        
    },
    onPullDownRefresh() {
        setTimeout(() => {
            uni.stopPullDownRefresh()
        }, 1000)
    },
    mounted() {
        
    },
    methods:{
        handleSwitch(e) {
            this.checked = e.detail.value
        },
        sliderChange(e) {
            this.sliderValue = e.detail.value
        },
        handleChangeGender(e){
            this.value = e
            console.log(this.value)
        },
        handleClick() {
            // console.log(this.name, this.age, this.gender, this.hobbies, this.valueCity)
            console.log(this.textarea)
        },
        handleGender(e) {
            this.gender = e.target.value
        },
        handleHobbies(e) {
            this.hobbies = e.target.value
        },
        handleChangeCity(e) {
            this.valueCity = e
            console.log(this.valueCity)
        }
    }
}
</script>

<style scoped>
    
</style>
相关推荐
uhakadotcom26 分钟前
Astro 框架:快速构建内容驱动型网站的利器
前端·javascript·面试
uhakadotcom30 分钟前
了解Nest.js和Next.js:如何选择合适的框架
前端·javascript·面试
uhakadotcom40 分钟前
Remix 框架:性能与易用性的完美结合
前端·javascript·面试
uhakadotcom1 小时前
Node.js 包管理器:npm vs pnpm
前端·javascript·面试
咖啡教室2 小时前
前端开发日常工作每日记录笔记(2019至2024合集)
前端·javascript
咖啡教室2 小时前
前端开发中JavaScript、HTML、CSS常见避坑问题
前端·javascript·css
市民中心的蟋蟀5 小时前
第五章 使用Context和订阅来共享组件状态
前端·javascript·react.js
逆袭的小黄鸭5 小时前
JavaScript 闭包:强大特性背后的概念、应用与内存考量
前端·javascript·面试
Mintopia5 小时前
Node.js 中 fs.readFile API 的使用详解
前端·javascript·node.js
Face5 小时前
事件循环
前端·javascript