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: '无' },
],
相关推荐
nn_(nana)34 分钟前
修改文件权限--- chmod ,vi/vim,查看文件内容,yum-软件包管理器,systemctl管理系统服务
前端
烛阴1 小时前
从零开始掌握C#核心:变量与数据类型
前端·c#
han_1 小时前
前端高频面试题之Vuex篇
前端·vue.js·面试
qq_415216252 小时前
vue3搭建项目yarn+vue3+webpack+less+element-plus
前端·webpack·less
天天向上10242 小时前
VueUse的使用
前端·vue.js·vscode
FREE技术2 小时前
学生成绩管理系统 基于java+springboot+vue实现前后端分离项目并附带万字文档(源码+数据库+万字详设文档+软件包+安装教程)
java·vue.js·spring boot·mysql
猪猪拆迁队3 小时前
前端图形引擎架构设计:双引擎架构设计
前端·后端·架构
宋辰月4 小时前
学习react第三天
前端·学习·react.js
bug总结4 小时前
更新原生小程序封装(新增缓存订阅)完美解决
前端·缓存·小程序
5335ld4 小时前
后端给的post 方法但是要求传表单数据格式(没有{})
开发语言·前端·javascript·vue.js·ecmascript