首页 > 其他分享 >vue 点击空白处才会改变右侧栏内容

vue 点击空白处才会改变右侧栏内容

时间:2023-01-12 14:57:52浏览次数:60  
标签:vue color height width 点击 position border 空白处 left

要实现如下功能:

点击左图中红框区域,改变右侧栏内容,从11111变成33333

点击右图中蓝框以外的空白区域,右侧栏内容变回1111111

               

 父组件中:

 

        // 点击空白处返回最初的右侧边栏内容
        handleALL(event){
          var one = document.getElementById("box1");
            var two = document.getElementById("box2");
            var three = document.getElementById("card");
            var four = document.getElementById("col");        
            if(!one.contains(event.target) && !two.contains(event.target) && !three.contains(event.target) && !four.contains(event.target)){
              this.$refs.dtwcardform.showType1 = true
              this.$refs.dtwcardform.showType2 = false
            }
               
        }

one two three four可以理解为图中蓝色框部分,排除掉这几个部分,剩下的空白区域被点击则改变右侧边栏内容

子组件完整代码:

<template>
  <div>    
    <el-card id="card" :body-style="{ padding: '2px' }" class="box-card">     
      <div class="hoverdiv">
        <img :src="input[0].name" class="image2" style="cursor:pointer;" @click="handleone">
        <el-input class="hoverinput" type="textarea" :rows="2" v-model="input[1].name" @click.native="tuNameDrawer = true" :placeholder="placeholder" maxlength="30" show-word-limit @focus="blurSearchFor()" @blur="handleInputBlur" ref="tuname" id="a" />
      </div>
      <div class="bottom clearfix" style="margin:5px 25px">
        <el-col :span="6">
          <img :src="input[0].name" class="image3" style="cursor:pointer;" @click="handleone">
        </el-col>
        <el-col :span="18">
          <el-input type="textarea" :rows="2" v-model="input[2].name" placeholder="编辑文本,最多显示30个字。编辑文本,最多显示30个字" maxlength="30" show-word-limit @blur="handleInputBlur" ref="tuintroduce" />
        </el-col>
      </div>
    </el-card>

    <!-- 右侧栏——设置 -->
    <section class="settings" v-show="showType1" id="box1">
      <div class="settings-header">
        <h3 class="herder-title">设置</h3>
      </div>
      <div class="settings-body">
        <el-card>
          <div>
            1111111111111111111111
          </div>
        </el-card>
      </div>
    </section>
    <!-- 右侧栏——图片设置 -->
    <section class="settings" v-show="showType2" id="box2">
      <div class="settings-header">
        <h3 class="herder-title">图片设置</h3>
      </div>
      <div class="settings-body">
        <el-card>
          <div>
            <p class="wenzi">333333333333333333333333</p>
          </div>
        </el-card>
      </div>
    </section>
  </div>
</template>

<script>
import editTableVue from '../../tool/gen/editTable.vue'

  export default {
    data(){
      return{
        input: [
          {name:require('../../../assets/images/tuwen2.jpg')},  // 0  图片
          {name:''},  // 1  编辑文本
          {name:''},  // 2  编辑文本描述
        ],
        tuNameDrawer: false,
        placeholder: '编辑文本,最多显示30个字。编辑文本,最多显示30个字',
        cursorIndex:'', 
        showType1: true,
        showType2: false,
        radio: 3,
      }
    },
    methods:{
      handleone(){
        this.showType1 = false
        this.showType2 = true
      },
      blurSearchFor(){
        if(this.placeholder == '编辑文本,最多显示30个字。编辑文本,最多显示30个字'){
          this.placeholder = ''
        }
      },
      //获取光标位置
      handleInputBlur(e){
        if(e.srcElement.id === 'a'){
          this.placeholder = '编辑文本,最多显示30个字。编辑文本,最多显示30个字'
        }
        this.cursorIndex = e.srcElement.selectionStart; 
      },
    },
 }
</script>

<style lang="scss">
.image2 {
  width: 100%;
  display: block;
  height: 260px;
}
.image3{
  width: 60px;
  display: block;
  height: 54px;
} 
.hoverdiv{
  position: relative;
}
.hoverinput{
  position: absolute;
  bottom: 0;
  left: 0;
  margin: 5px 5px; 
  cursor: pointer;
}
.hoverdiv .el-textarea__inner{
  height: 60px;
  /* 使input框的背景变透明 */
  background-color: rgba(144, 147, 153, 0.2);
  /* 使边框也变透明 */
  border-color: rgba(144, 147, 153, 0.2);
  /* 给边框加阴影能够使其有立体感 */
  // box-shadow: 2px 2px 0 0 rgba(0,0,0,0.2);
  /* 改变获取焦点后的竖线颜色 */
  // caret-color: rgba(0, 255, 255,0.8);
  color:#FFFFFF;
  &::placeholder{
    font-size: 16px;
    color:#FFFFFF;
  }
}
.hoverdiv .el-input__count{
    background-color: transparent;
  }
 
.bottom {
  margin-top: 13px;
  line-height: 12px;
  padding: 2px;
}
.clearfix:before,
.clearfix:after {
    display: table;
    content: "";
}

.clearfix:after {
    clear: both
}
.text1 {
  font-size: 15px;
  color: black;
  line-height: 18px;
}

.point{
  cursor: pointer;
}

.button{
  width: 100%;
}

.map {
  width: 100%;
  height: 300px;
  margin-top: 20px;
}
.bm-view{
  width: 100%;
  height: 300px;
  margin-top: 20px;   
}
.settings{
  position: fixed;
  top: 60px;
  bottom: 0;
  right: 0;
  width: 380px;
  border: 1px solid #dcdcdc;
  border-radius: 2px;
  background-color: #f8f8fa;
  z-index: 2;
}
.settings-header{
  position: relative;
  height: 35px;
  line-height: 35px;
  margin-left: 8px;
  margin-right: 8px;
  vertical-align: middle;
  border-bottom: 1px solid #dcdcdc;
  box-sizing: border-box;
  z-index: 10;
}
.herder-title{
  text-align: left;
  padding-left: 5px;
  font-weight: 600;
  font-size: 14px;
  color: #29304e;
  position: relative;
}
.herder-title:before{
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: #1890ff;
  opacity: 1;
  border-radius: 2px;
}
.settings-body{
  padding-left: 16px;
  padding-right: 16px;
  position: absolute;
  top: 60px;
  bottom: 0;
  width: 100%;
  box-sizing: border-box;
  overflow-y: auto;
}
.wenzi{
  text-align: left;
}
</style>

参考:https://www.cnblogs.com/zhifei9/p/15216308.html

标签:vue,color,height,width,点击,position,border,空白处,left
From: https://www.cnblogs.com/silvia-earl/p/17046638.html

相关文章

  • 封装vue2自定义指令-滚动到底部加载更多
    前置知识1.clientHeight:(1)含义:只读属性,表示元素的内部高度(元素可见高度),单位为像素。(2)从盒子模型角度看:包含padding,但不包含border,margin以及水平滚动条。(3)注意:内联元......
  • vue-2.5.17.js:8553 You are running Vue in development mode. Make sure to turn on
    前言刚开始搭建VUE前端出一个警告不影响运行-TemplatesshouldonlyberesponsibleformappingthestatetotheUI.Avoidplacingtagswithside-effectsinyo......
  • VUE 回车换行提交表单 跑马灯效果 只允许文本框中输入0-9数字
    导入vue.js<scriptsrc="vue-2.5.17.js"></script>1.回车换行提交表单方法一<divid="app"> <inputtype="text"v-model="name"@keydown.13="mouse(0)">{{name}}<......
  • vue 3 引入 scss
    安装必要的依赖:   调用: 效果: ......
  • Vue基础-课程介绍
     ......
  • vite+vue3搭建项目流程
    1.安装Node2.使用npm创建目录npmcreatevite@latest项目名称----templatevue3.配置@路径(path模块是node.js内置的功能,但是node.js本身并不支持ts,所以需要手......
  • vue 文件下载与图片下载
    文件下载window.open(url,'_self')图片下载点击查看代码handleDownload(imgSrc,name){ constimage=newImage(); //解决跨域Canvas污染问题 image.setAttri......
  • vue动态挂载组件
    平时我们渲染组件都是通过路由的方式。但有时候不太满足需要,需要我们手动去挂载组件。方式如下:通过调用一个方法去实现动态挂载组件:importVuefrom"vue"importj......
  • vue 如何监测真实Dom是否加载完成
    1、充分利用浏览器的队列特性://声明定时器vartimer=null//检查dom是否执行完成functioncheck(){//onMounted挂载完dom获取为空,真实dom在对象中......
  • vue的seo
    我们知道,常规用Vue/React开发的是SPA应用。但是天然的单页面应用SEO就是不好。虽然说现在也有各种技术可以改善了,比如使用服务端渲染、静态页面生成,不过也存在各种......