vue-signature-pad在vue中實(shí)現(xiàn)電子簽名效果。

image.png
首頁需要下載依賴包
npm install --save vue-signature-pad

這里使用的是全局引用組件在main.js

import Vue from "vue";
import VueSignaturePad from "vue-signature-pad";
Vue.use(VueSignaturePad);

引用組件

首頁需要下載依賴包
npm install --save vue-signature-pad

這里使用的是全局引用組件在main.js

import Vue from "vue";
import VueSignaturePad from "vue-signature-pad";
Vue.use(VueSignaturePad);

引用組件

  <template>
  <el-dialog
    :title="mainTitle"
    :visible.sync="editVisible"
    :modal-append-to-body="false"
    width="840px"
    @open="dlgOpen"
    @closed="dlgClosed"
    :close-on-click-modal="false"
  >
    <div id="app">
      <div class="container">
        <div class="row">
          <div class="col-12 mt-2">
            <VueSignaturePad
              id="signature"
              width="95%"
              height="400px"
              ref="signaturePad"
              :options="options"
            />
          </div>
        </div>
        <el-row>
          <el-col :span="4">
            <div class="grid-content bg-purple">
              <el-button type="primary" plain @click="undo">撤銷</el-button>
            </div>
          </el-col>
          <el-col :span="4"
            ><div class="grid-content bg-purple-light">
              <el-button type="success" plain @click="save">保存</el-button>
            </div>
          </el-col>
          <el-col :span="4"
            ><div class="grid-content bg-purple">
              <el-button type="warning" plain @click="change">換色</el-button>
            </div>
          </el-col>
          <el-col :span="4"
            ><div class="grid-content bg-purple-light">
              <el-button type="danger" plain @click="resume">重置</el-button>
            </div>
          </el-col>

          <el-col :span="4"
            ><div class="grid-content">
              <el-button type="danger" plain @click="close">關(guān)閉</el-button>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </el-dialog>
</template>
<script>
export default {
  data() {
    return {
      editVisible: false,
      mainTitle: "用戶簽名",
      options: {
        penColor: "#000",
      },
    };
  },
  methods: {
    init(id) {
      this.editVisible = true;
    },
    undo() {
      this.$refs.signaturePad.undoSignature();
    },
    save() {
      const { isEmpty, data } = this.$refs.signaturePad.saveSignature();

      alert("Open DevTools see the save data.");
      console.log(isEmpty);
      console.log(data);
    },
    //切換顏色
    change() {
      if (this.options.penColor == "#00f") {
        this.options = {
          penColor: "#c0f",
        };
      } else {
        this.options = {
          penColor: "#00f",
        };
      }
    },
    //清除重置
    resume() {
      this.$refs.signaturePad.clearSignature();
    },
    //關(guān)閉
    close() {
      this.editVisible = false;
    },
  },
};
</script>
<style lang="scss" scoped>
#signature {
  border: double 3px transparent;
  border-radius: 2px;
  background-image: linear-gradient(white, white),
    radial-gradient(circle at top left, #4bc5e8, #9f6274);
  background-origin: border-box;
  background-clip: content-box, border-box;
  margin-bottom: 15px;
  margin-left: 19px;
}
</style>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容