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: '无' },
],
相关推荐
0思必得02 分钟前
[Web自动化] Selenium模拟用户的常见操作
前端·python·selenium·自动化
Apifox.15 分钟前
测试用例越堆越多?用 Apifox 测试套件让自动化回归更易维护
运维·前端·后端·测试工具·单元测试·自动化·测试用例
玉梅小洋30 分钟前
Chrome设置链接自动跳转新标签页而不是覆盖
前端·chrome
EndingCoder36 分钟前
反射和元数据:高级装饰器用法
linux·运维·前端·ubuntu·typescript
Marshmallowc40 分钟前
React性能优化:useState初始值为什么要用箭头函数?深度解析Lazy Initialization与Fiber机制
前端·react.js·性能优化·前端框架·react hooks
Coder_Boy_43 分钟前
基于SpringAI的在线考试系统-试卷管理模块完整优化方案
前端·人工智能·spring boot·架构·领域驱动
摇滚侠1 小时前
Node.js 零基础教程,Node.js 和 NPM 的安装与使用
前端·npm·node.js
谢尔登1 小时前
Vue3架构设计——调度系统
前端·javascript·vue.js
码农研究僧1 小时前
ruoyi+vue2的前端Demo(不分页、前端分页、后端分页)
前端·vue2·ruoyi
Kratzdisteln1 小时前
【1902】0121-1 Dify工作流节点详细配置(方案B最终版)
java·前端·javascript