vue 實現(xiàn)在線簽名

安裝:

npm install vue-esign --save

使用:

? ?1. main.js 中引入

?importvueEsignfrom'vue-esign?'

?Vue.use(vueEsign)

? ? 2.頁面中使用?必須設(shè)置?ref?,用來調(diào)用組件的兩個內(nèi)置方法?reset()?和?generate()

<el-row>

? ? ? <el-col :span="3" style="display: flex;">

? ? ? ? <div class="esign-group">

? ? ? ? ? <label>畫筆粗細:</label>

? ? ? ? ? <el-select? v-model="lineWidth" placeholder="請選擇" size="small">

? ? ? ? ? ? ? <el-option key="2" label="2" value="2"></el-option>

? ? ? ? ? ? ? <el-option key="4" label="4" value="4"></el-option>

? ? ? ? ? ? ? <el-option key="6" label="6" value="6"></el-option>

? ? ? ? ? ? ? <el-option key="8" label="8" value="8"></el-option>

? ? ? ? ? ? ? <el-option key="10" label="10" value="10"></el-option>

? ? ? ? ? </el-select>

? ? ? ? </div>

? ? ? </el-col>

? ? ? <el-col :span="3">

? ? ? ? <div class="esign-group">

? ? ? ? ? <label>畫筆顏色:</label>

? ? ? ? ? <el-color-picker v-model="lineColor" size="small"></el-color-picker>

? ? ? ? </div>

? ? ? </el-col>

? ? ? <el-col :span="3">

? ? ? ? <div class="esign-group">

? ? ? ? ? <label>畫布背景:</label>

? ? ? ? ? <el-color-picker v-model="bgColor" size="small"></el-color-picker>

? ? ? ? </div>

? ? ? </el-col>

? ? ? <el-col :span="3">

? ? ? ? <div class="esign-group">

? ? ? ? ? <label>是否裁剪:</label>

? ? ? ? ? <el-switch

? ? ? ? ? ? v-model="isCrop">

? ? ? ? ? </el-switch>

? ? ? ? </div>

? ? ? </el-col>

? ? </el-row>

? <vue-esign ref="esign" :width="800" :height="300" :isCrop="isCrop" :lineWidth="lineWidth" :lineColor="lineColor"? ?:bgColor.sync="bgColor" />

? <el-button type="primary" size="small" @click="handleReset">清空畫板</el-button>

? ? <el-button type="success" size="small" @click="handleGenerate">生成圖片</el-button>

data () {

? return {

? ? lineWidth: 6,

? ? lineColor: '#000000',

? ? bgColor: '',

? ? resultImg: '',

? ? isCrop: false

? }

},

methods: {

? handleReset () {

? ? this.$refs.esign.reset()

? },

? handleGenerate () {

? ? this.$refs.esign.generate().then(res => {

? ? ? this.resultImg = res

? ? }).catch(err => {

? ? ? alert(err) // 畫布沒有簽字時會執(zhí)行這里 'Not Signned'

? ? })

? }

}

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

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

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