最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue實現(xiàn)指定區(qū)域自由拖拽、打印功能

 更新時間:2022年04月07日 08:31:29   作者:Rulyc  
這篇文章主要為大家詳細介紹了vue實現(xiàn)指定區(qū)域自由拖拽、打印功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了vue實現(xiàn)指定區(qū)域自由拖拽、打印功能的具體代碼,供大家參考,具體內(nèi)容如下

先看下效果圖,實現(xiàn)指定區(qū)域內(nèi)內(nèi)容自由拖拽,不超出。動態(tài)設(shè)置字體顏色及字號;設(shè)置完成實現(xiàn)打印指定區(qū)域內(nèi)容,樣式不丟失。

1、運行命令npm i vue-draggable-resizable -S, 安裝拖拽插件vue-draggable-resizable,并引入使用(下面引入是放入main.js文件中)

import VueDraggableResizable from 'vue-draggable-resizable'

// optionally import default styles
import 'vue-draggable-resizable/dist/VueDraggableResizable.css'

Vue.component('vue-draggable-resizable', VueDraggableResizable)

2、 實現(xiàn)指定區(qū)域內(nèi)自由拖拽代碼:

<div class="p-event" id="print" style="border: 1px solid red; box-sizing: border-box; height: 500px; width: 900px;">
? ? ? ? <template v-for="(item, index) in list">
? ? ? ? ? <vue-draggable-resizable
? ? ? ? ? ? parent=".p-event"
? ? ? ? ? ? :grid="[10,10]"
? ? ? ? ? ? :x="item.x"
? ? ? ? ? ? :y="item.y"
? ? ? ? ? ? :left="form.paddingLeft"
? ? ? ? ? ? :key="item+index"
? ? ? ? ? ? :parent="true"
? ? ? ? ? ? w="auto"
? ? ? ? ? ? h="auto"
? ? ? ? ? ? @dragging="onDrag"
? ? ? ? ? ? @resizing="onResize">
? ? ? ? ? ? <p :style="{ fontSize: item.fontSize, color: item.color, lineHeight: item.lineHeight }">{{ item.name }}</p>
? ? ? ? ? </vue-draggable-resizable>
? ? ? ? </template>
</div>

class=“p-event”, parent=".p-event", :parent=“true” 是為了設(shè)置父元素,且拖拽區(qū)域不能超過父元素。

x與y采用隨機數(shù),是為了初次進入,不會多個數(shù)據(jù)不會擠在左上角。

3、打印指定區(qū)域內(nèi)內(nèi)容

?/** 打印方法 */
? ? doPrint() {
? ? ? const subOutputRankPrint = document.getElementById('print')
? ? ? const newContent = subOutputRankPrint.innerHTML
? ? ? const oldContent = document.body.innerHTML
? ? ? document.body.innerHTML = newContent
? ? ? window.print()
? ? ? window.location.reload()
? ? ? document.body.innerHTML = oldContent
? ? ? return false
? ? },

去掉頁頭頁尾

<style media="print" scoped>
/** 去掉頁頭和頁尾 */
@page {
? size: auto; ?/* auto is the initial value */
? margin: 0mm; /* this affects the margin in the printer settings */
}
</style>

整體代碼如下:

<template>
? <div style="padding:30px;">
? ? <h1>拖拽</h1>
? ? <el-button @click="doPrint">打印</el-button>
? ? <el-form ref="form" :model="form" label-width="80px">
? ? ? <el-form-item label="字號設(shè)置">
? ? ? ? <el-row :gutter="20">
? ? ? ? ? <el-col :span="4">
? ? ? ? ? ? <el-select v-model="form.name" @change="changeName();changeVal()">
? ? ? ? ? ? ? <el-option v-for="(item,index) in list" :label="item.label" :key="index+item.label" :value="item.name"></el-option>
? ? ? ? ? ? </el-select>
? ? ? ? ? </el-col>
? ? ? ? ? <el-col :span="4">
? ? ? ? ? ? <el-select v-model="form.selectVal" @change="changeHeight">
? ? ? ? ? ? ? <el-option label="字體大小" value="fontSize"></el-option>
? ? ? ? ? ? ? <el-option label="行高設(shè)置" key="index+item.value" value="lineHeight"></el-option>
? ? ? ? ? ? </el-select>
? ? ? ? ? </el-col>
? ? ? ? ? <el-col :span="4">
? ? ? ? ? ? <el-select v-model="form.fontSize" @change="changeVal">
? ? ? ? ? ? ? <el-option v-for="(item,index) in sizeList" :key="index+item.value" :label="item.label" :value="item.value"></el-option>
? ? ? ? ? ? </el-select>
? ? ? ? ? </el-col>
? ? ? ? ? <el-col :span="4">
? ? ? ? ? ? <el-color-picker v-model="form.color" @change="changeVal"></el-color-picker>
? ? ? ? ? </el-col>
? ? ? ? </el-row>
? ? ? </el-form-item>
? ? </el-form>
? ? ? <div class="p-event" id="print" style="border: 1px solid red; box-sizing: border-box; height: 500px; width: 900px;">
? ? ? ? <template v-for="(item, index) in list">
? ? ? ? ? <vue-draggable-resizable
? ? ? ? ? ? parent=".p-event"
? ? ? ? ? ? :grid="[10,10]"
? ? ? ? ? ? :x="item.x"
? ? ? ? ? ? :y="item.y"
? ? ? ? ? ? :left="form.paddingLeft"
? ? ? ? ? ? :key="item+index"
? ? ? ? ? ? :parent="true"
? ? ? ? ? ? w="auto"
? ? ? ? ? ? h="auto"
? ? ? ? ? ? @dragging="onDrag"
? ? ? ? ? ? @resizing="onResize">
? ? ? ? ? ? <p :style="{ fontSize: item.fontSize, color: item.color, lineHeight: item.lineHeight }">{{ item.name }}</p>
? ? ? ? ? </vue-draggable-resizable>
? ? ? ? </template>
? ? ? </div>
? </div>
</template>

<script>
export default {
? data: function() {
? ? return {
? ? ? width: 0,
? ? ? height: 0,
? ? ? x: 0,
? ? ? y: 0,
? ? ? form: {
? ? ? ? name: '',
? ? ? ? fontSize: '',
? ? ? ? selectVal: '',
? ? ? ? color: '',
? ? ? ? paddingTop: 20,
? ? ? ? paddingBottom: 0,
? ? ? ? paddingLeft: 0,
? ? ? ? paddingRight: 0
? ? ? },
? ? ? sizeList: [], // 字體號數(shù)組
? ? ? apiArr: [ // 后期從接口中獲取name集合
? ? ? ? { name: '公司名稱' },
? ? ? ? { name: '抬頭' },
? ? ? ? { name: '公司簡介' }
? ? ? ],
? ? ? list: [] // apiArr帶上所有屬性的集合
? ? }
? },
? mounted() {
? ? // 字號數(shù)組獲取
? ? for (let i = 12; i <= 48; i++) {
? ? ? this.sizeList.push({ label: `${i}px`, value: `${i}px` })
? ? }
? ? // 網(wǎng)格上的數(shù)據(jù)獲取
? ? for (const it of this.apiArr) {
? ? ? this.list.push({
? ? ? ? name: it.name, // 表名對應(yīng)的值
? ? ? ? label: it.name, // 表名
? ? ? ? fontSize: '16px', // 默認字體
? ? ? ? lineHeight: 'normal', // 默認行高
? ? ? ? color: '#000000', // 默認顏色
? ? ? ? x: Math.floor(Math.random() * (800 - 10)) + 10, // x默認值
? ? ? ? y: Math.floor(Math.random() * (450 - 10)) + 10 // y 默認值
? ? ? })
? ? }
? },
? methods: {
? ? /** 打印方法 */
? ? doPrint() {
? ? ? const subOutputRankPrint = document.getElementById('print')
? ? ? const newContent = subOutputRankPrint.innerHTML
? ? ? const oldContent = document.body.innerHTML
? ? ? document.body.innerHTML = newContent
? ? ? window.print()
? ? ? window.location.reload()
? ? ? document.body.innerHTML = oldContent
? ? ? return false
? ? },
? ? onResize: function(x, y, width, height) {
? ? ? this.x = x
? ? ? this.y = y
? ? ? this.width = width
? ? ? this.height = height
? ? },
? ? onDrag: function(x, y) {
? ? ? this.x = x
? ? ? this.y = y
? ? },
? ? /** 選擇列下拉框 */
? ? changeName() {
? ? ? this.form.fontSize = ''
? ? ? this.form.color = ''
? ? },
? ? changeHeight() {
? ? ? this.form.fontSize = ''
? ? },
? ? /** 下拉框改變的時候進行動態(tài)設(shè)置樣式 */
? ? changeVal() {
? ? ? if (this.form.name && this.form.fontSize && this.form.selectVal === 'fontSize') { this.commonMethod('fontSize') }
? ? ? if (this.form.name && this.form.fontSize && this.form.selectVal === 'lineHeight') { this.commonMethod('lineHeight') }
? ? ? if (this.form.name && this.form.color) { this.commonMethod('color') }
? ? },
? ? /** 公共的設(shè)置樣式方法 */
? ? commonMethod(val) {
? ? ? for (const it of this.list) {
? ? ? ? if (it.label === this.form.name) {
? ? ? ? ? if (val === 'lineHeight') {
? ? ? ? ? ? it[val] = this.form.fontSize
? ? ? ? ? } else {
? ? ? ? ? ? it[val] = this.form[val]
? ? ? ? ? }
? ? ? ? }
? ? ? }
? ? }
? }
}
</script>

<style scoped>
/** 這里vdr的樣式設(shè)置是為了當(dāng)沒有選中目標(biāo)文字時,去掉默認的虛線框,只有選中的時候才有虛線框 */
.vdr {
? border: none;
}
.handle, .active.vdr {
? border: 1px dashed #000;
}
#print {
? position: relative;
? /** 網(wǎng)格樣式 */
? background: linear-gradient(-90deg, rgba(0, 0, 0, 0.1) 1px, transparent 1px) 0% 0% / 10px 10px, linear-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 1px) 0% 0% / 10px 10px;
}
</style>
<style media="print" scoped>
/** 去掉頁頭和頁尾 */
@page {
? size: auto; ?/* auto is the initial value */
? margin: 0mm; /* this affects the margin in the printer settings */
}
</style>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue2配置scss的方法步驟

    vue2配置scss的方法步驟

    這篇文章主要介紹了vue2配置scss的方法步驟,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • 基于vue實現(xiàn)分頁效果

    基于vue實現(xiàn)分頁效果

    這篇文章主要介紹了基于vue實現(xiàn)分頁效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • vue中的主動觸發(fā)點擊事件

    vue中的主動觸發(fā)點擊事件

    這篇文章主要介紹了vue中的主動觸發(fā)點擊事件,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • 在vue中實現(xiàn)echarts隨窗體變化

    在vue中實現(xiàn)echarts隨窗體變化

    這篇文章主要介紹了在vue中實現(xiàn)echarts隨窗體變化,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • vue實現(xiàn)簡單的跑馬燈效果

    vue實現(xiàn)簡單的跑馬燈效果

    這篇文章主要為大家詳細介紹了vue實現(xiàn)簡單的跑馬燈效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • Vue請求JSON Server服務(wù)器數(shù)據(jù)的實現(xiàn)方法

    Vue請求JSON Server服務(wù)器數(shù)據(jù)的實現(xiàn)方法

    這篇文章主要介紹了Vue請求JSON Server服務(wù)器數(shù)據(jù)的實現(xiàn)方法,需要的朋友可以參考下
    2018-11-11
  • vue3中的watch()的用法和具體作用

    vue3中的watch()的用法和具體作用

    這篇文章主要介紹了vue3中的watch()的用法和具體作用,通過合理和熟練使用watch()方法,開發(fā)者可以更加高效地完成前端開發(fā)工作,需要的朋友可以參考下
    2023-04-04
  • 使用Vue-Router 2實現(xiàn)路由功能實例詳解

    使用Vue-Router 2實現(xiàn)路由功能實例詳解

    vue-router 2只適用于Vue2.x版本,下面我們是基于vue2.0講的如何使用vue-router 2實現(xiàn)路由功能,需要的朋友可以參考下
    2017-11-11
  • vue實現(xiàn)循環(huán)滾動列表

    vue實現(xiàn)循環(huán)滾動列表

    這篇文章主要為大家詳細介紹了vue實現(xiàn)循環(huán)滾動列表,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • Vue Promise解決回調(diào)地獄問題實現(xiàn)方法

    Vue Promise解決回調(diào)地獄問題實現(xiàn)方法

    這篇文章主要介紹了Vue Promise解決回調(diào)地獄問題,總的來說這并不是一道難題,那為什么要拿出這道題介紹?拿出這道題真正想要傳達的是解題的思路,以及不斷優(yōu)化探尋最優(yōu)解的過程。希望通過這道題能給你帶來一種解題優(yōu)化的思路
    2023-01-01

最新評論

龙岩市| 平江县| 新津县| 同江市| 大竹县| 新闻| 同心县| 济源市| 扶绥县| 古丈县| 瓮安县| 德安县| 临西县| 威宁| 绿春县| 甘肃省| 灯塔市| 理塘县| 肇东市| 澄江县| 甘孜| 嘉鱼县| 胶南市| 城固县| 抚顺县| 故城县| 如东县| 巴中市| 兰溪市| 镇雄县| 山东省| 正宁县| 塔城市| 溧水县| 连江县| 巴彦县| 华蓥市| 东光县| 香港| 旺苍县| 甘泉县|