vue2签名版、画板 组件

<template>
  <!-- 签名版 -->
  <div class="signature-edition">
    <el-dialog title="签名版" :visible.sync="dialogVisible" width="50%">

      <div class="signature-edition-content">
        <vue-esign ref="esign" :width="800" :height="300" :isCrop="isCrop" :lineWidth="lineWidth"
          :lineColor="lineColor" />
      </div>

      <div slot="footer" class="dialog-footer">
        <custom-button confirmText="取消" type="cancel" @click.native="dialogVisible = false"></custom-button>
        <custom-button confirmText="重新签名" type="confirm" @click.native="handleReset"
          style="margin:0 .25rem"></custom-button>
        <custom-button confirmText="确定" type="confirm" @click.native="handleGenerate"></custom-button>
      </div>

    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'SignatureEdition',
  data() {
    return {
      dialogVisible: false,
      lineWidth: 6,
      lineColor: '#000000',
      bgColor: '#F8F8F8',
      resultImg: '',
      isCrop: false
    }
  },
  methods: {
    show() {
      this.dialogVisible = true;
    },
    close() {
      this.dialogVisible = false;
    },
    handleReset() {
      this.$refs['esign'].reset() //清空画布
    },
    handleGenerate() {
      this.$refs['esign'].generate().then(res => {
        this.resultImg = res // 得到了签字生成的base64图片
        console.log(111, this.resultImg);
      }).catch(err => { //  没有签名,点击生成图片时调用
        this.$message({
          message: err + ' 未签名!',
          type: 'warning'
        })
        alert(err) // 画布没有签字时会执行这里 'Not Signned'
      })
    }
  }
}
</script>
<style lang="scss">
.signature-edition {

  .el-dialog {
    border-radius: .25rem;
  }

  .el-dialog__title {
    font-weight: bold;
    color: #000000;
  }

  .signature-edition-content {
    background-color: #F8F8F8;

    >div {
      &:first-child {
        color: #000000;
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: .25rem;

        >span {
          &:first-child {
            font-weight: bold;
            font-size: 16px;
            color: #000000;
          }

          &:last-child {
            font-size: 16px;
            color: #999999;
          }
        }
      }

      &:not(:first-child) {
        font-weight: bold;
        font-size: 14px;
        color: #000000;
        line-height: 2;
      }
    }
  }


  .dialog-footer {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue 2和Vue 3中,组件传值的方式有一些差异。下面我将介绍Vue 2和Vue 3中常用的几种组件传值方式: Vue 2中的组件传值方式: 1. Props:通过在父组件中使用属性绑定的方式将数据传递给子组件。父组件通过在子组件标签上绑定属性,并在子组件中通过props选项声明接收该属性。父组件可以在模板中直接使用子组件的属性。 2. 自定义事件:父组件可以通过`$emit`方法触发自定义事件,并传递数据给子组件。子组件通过`$on`方法监听父组件触发的事件,并在事件处理函数中接收数据。 3. Vuex:Vuex是Vue的状态管理库,可以在全局共享数据。父组件可以将数据存储在Vuex的状态管理中,并在子组件中通过计算属性或直接从Vuex中获取数据。 Vue 3中的组件传值方式: 1. Props:与Vue 2相同,通过在父组件中使用属性绑定的方式将数据传递给子组件。但是在Vue 3中,子组件需要使用`defineProps`来声明接收属性。 2. 自定义事件:与Vue 2相同,父组件可以通过`$emit`方法触发自定义事件,并传递数据给子组件。子组件通过`$on`方法监听父组件触发的事件,并在事件处理函数中接收数据。 3. Provide/Inject:父组件通过provide选项提供数据,然后子组件通过inject选项注入数据。这样可以在整个组件树中共享数据,而不需要显式传递。 需要注意的是,Vue 3中还引入了Composition API,通过`setup`函数来组织组件的逻辑。在`setup`函数中,可以使用`ref`和`reactive`等函数来创建响应式数据,并通过`props`参数接收父组件传递的属性。 以上是Vue 2和Vue 3中常用的组件传值方式,根据具体需求和场景选择合适的方式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值