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: '无' },
],
相关推荐
inquisiter8 分钟前
KernelGpt的部分尝试
java·前端·apache
the局外人30 分钟前
用 TRAE 把 Markdown文档 搬到微信公众号
前端
Autumn_ing31 分钟前
AI原型设计工具怎么选?可编辑原型与可运行前端适合什么场景
前端·小程序·产品经理·代码·codex·墨刀ai客户端·ai原型
夕阳_醉了1 小时前
前端通用组件开发全指南|从 0 到 1 打造稳定可复用的业务组件
前端
Amos_Web1 小时前
Rspack 源码解析(三十):SourceMapDevToolPlugin 如何生成并关联 source map
前端
console.log('npc')1 小时前
从0到1实现任务评价统计功能:React + TypeScript 实战指南(小白注释版)
前端·react.js·typescript
IT_陈寒1 小时前
为什么你应该学习React?
前端·人工智能·后端
ZoeLandia1 小时前
React04:事件处理与受控表单
开发语言·前端·react.js·typescript
亿元程序员2 小时前
用AI做了一款微信小游戏,却发现上传不了
前端
Ai-_Man2 小时前
我需要批量导出Poe左边栏所有对话,而不是一条具体的对话内容,你们AI导出鸭可以吗?
开发语言·前端·javascript·人工智能·小程序