Vue 自定义仿word表单录入之单选按钮组件

因项目需要,要实现仿word方式录入数据,要实现鼠标经过时才显示编辑组件,预览及离开后则显示具体的文字。

鼠标经过时显示

正常显示及离开时显示

组件代码

javascript 复制代码
<template >
    <div class="pager-input flex  border-box full-width flex-center-sp"   >
        <div class="font-l border-box text margin-left-m " style="font-family: FangSong;">{{text}}</div>
        <div  v-if="val === ''" class="color-white textplus" >请输入</div>
        <div class="input flex full-width hidden flex-center-sp">
            <div v-for="item in data" class="item flex border-box flex-center-cz ">
                <input :name="dataId" type="radio" v-model="val" @change="change(item.value)"  :value="item.value">
                <div class="flex flex-center-sp" >{{item.text}}</div>
             </div>
        </div>
    </div>
</template>

<script>

    import {getNewId} from '@/utils/sysUtils'
    export default{
        name:'PaperRadioBoxList',
        created() {
            this.dataId = getNewId();
        },
        data() {
            return {
                dataId: "",
                text:"",
                val:"",
            }
        },
        props: {
            data:{},
            value:{}
        },
        model: {
            prop: "value",
            event: "change"
        },
        mounted() {
            let find = this.data.filter(d=>d.value == this.val);
            if (find.length >= 0) {
                this.text = find[0].text;
            }
        },
        watch:{
            value:{
                handler(newValue) {
                    this.val =  newValue;
                    
                },
                immediate: true,
                deep: true   //深度监听                
            },

        },
        methods:{
            change(item) {
                this.val = item;                
                 let find = this.data.filter(d=>d.value === item);
                 if (find.length > 0) {
                    this.text = find[0].text;
                 }
                console.log(this.val);
                this.$emit("change", this.val)
            }
        }
    }
</script>

<style scoped>

    .pager-input:hover .text   {
        display: none;
    }

    .pager-input:hover .textplus   {
        display: none;
    }

    .pager-input:hover .input   {
        display: flex;
    }

    .item input {
        width: 18px;
        height: 18px;

    }

    


</style>

引用组件,支持数据双向绑定

javascript 复制代码
<PaperRadioBoxList :data="yesnoData"  v-model="paperData.punishment1"></PaperRadioBoxList>


yesnoData:
[
    { value: 1, text: '有' },
    { value: 0, text: '无' },
],
相关推荐
哈哈~haha3 分钟前
Step 14: Custom CSS and Theme Colors 自定义CSS类
前端·css·ui5
Ndmzi11 分钟前
Matlab编程技巧:自定义Simulink菜单(理解补充)
前端·javascript·python
我命由我1234526 分钟前
VSCode - VSCode 修改文件树缩进
前端·ide·vscode·前端框架·编辑器·html·js
SoaringHeart1 小时前
Flutter组件封装:验证码倒计时按钮 TimerButton
前端·flutter
San30.1 小时前
深入理解 JavaScript OOP:从一个「就地编辑组件」看清封装、状态与原型链
开发语言·前端·javascript·ecmascript
AAA阿giao1 小时前
JavaScript 原型与原型链:从零到精通的深度解析
前端·javascript·原型·原型模式·prototype·原型链
烛阴2 小时前
C#异常概念与try-catch入门
前端·c#
钮钴禄·爱因斯晨2 小时前
# 企业级前端智能化架构:DevUI与MateChat融合实践深度剖析
前端·架构
摆烂工程师2 小时前
2025年12月最新的 Google AI One Pro 1年会员教育认证通关指南
前端·后端·ai编程
Gavin在路上2 小时前
DDD之用事件风暴重构“电商订单履约”(11)
java·前端·重构