欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

前端開發(fā)指南之vue-grid-layout的使用實(shí)例

 更新時(shí)間:2022年09月01日 10:54:35   作者:馮浩(grow?up)  
vue-grid-layout是一個(gè)vue柵格拖動(dòng)布局的組件,下面這篇文章主要給大家介紹了關(guān)于前端開發(fā)指南之vue-grid-layout使用的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下

前言

Vue Grid Layout官方文檔

Vue Grid Layout中文文檔

可通過拖拽改變布局(如果我們做簡(jiǎn)易開發(fā),通過拖拽組件形成頁面或者有這個(gè)需求就是非常實(shí)用的了)

因?yàn)関ue-grid-layout是vue2版本的 但自己用的是vue3版本,所以要安裝vue3的依賴和相關(guān)配置

效果圖

一、vue中簡(jiǎn)單案例

1、安裝組件 NPM

npm install vue-grid-layout --save

Yarn

yarn add vue-grid-layout

2、vue文件

<template>
  <div style="width: 100%; height: 100%">
    <div class="layoutJSON">
      顯示為
      <code>[x, y, w, h]</code>
      :
      <div class="columns">
        <div v-for="(item, indexVar) in layout" :key="indexVar">
          <b>{{ item.i }}</b>
          : [{{ item.x }}, {{ item.y }}, {{ item.w }}, {{ item.h }}]
        </div>
      </div>
    </div>
    <hr />
    <input v-model="draggable" type="checkbox" />
    可拖動(dòng)
    <input v-model="resizable" type="checkbox" />
    可調(diào)整大小
    <input v-model="responsive" type="checkbox" />
    鏡像
    <br />
    <div style="width: 100%; margin-top: 10px; height: 100%">
      <grid-layout
        :col-num="12"
        :is-draggable="draggable"
        :is-resizable="resizable"
        :layout="layout"
        :responsive="responsive"
        :row-height="30"
        :use-css-transforms="true"
        :vertical-compact="true"
      >
        <grid-item
          v-for="(item, indexVar) in layout"
          :key="indexVar"
          :h="item.h"
          :i="item.i"
          :static="item.static"
          :w="item.w"
          :x="item.x"
          :y="item.y"
        >
          <span class="text">{{ item.i }}</span>
        </grid-item>
      </grid-layout>
    </div>
  </div>
</template>

<script>
  import { GridLayout, GridItem } from 'vue-grid-layout'
  export default {
    components: {
      GridLayout,
      GridItem,
    },
    data() {
      return {
        layout: [
          { x: 0, y: 0, w: 2, h: 2, i: '0' },
          { x: 2, y: 0, w: 2, h: 4, i: '1' },
          { x: 4, y: 0, w: 2, h: 5, i: '2' },
          { x: 6, y: 0, w: 2, h: 3, i: '3' },
          { x: 8, y: 0, w: 2, h: 3, i: '4' },
          { x: 10, y: 0, w: 2, h: 3, i: '5' },
          { x: 0, y: 5, w: 2, h: 5, i: '6' },
          { x: 2, y: 5, w: 2, h: 5, i: '7' },
          { x: 4, y: 5, w: 2, h: 5, i: '8' },
          { x: 6, y: 4, w: 2, h: 4, i: '9' },
          { x: 8, y: 4, w: 2, h: 4, i: '10' },
          { x: 10, y: 4, w: 2, h: 4, i: '11' },
          { x: 0, y: 10, w: 2, h: 5, i: '12' },
          { x: 2, y: 10, w: 2, h: 5, i: '13' },
          { x: 4, y: 8, w: 2, h: 4, i: '14' },
          { x: 6, y: 8, w: 2, h: 4, i: '15' },
          { x: 8, y: 10, w: 2, h: 5, i: '16' },
          { x: 10, y: 4, w: 2, h: 2, i: '17' },
          { x: 0, y: 9, w: 2, h: 3, i: '18' },
          { x: 2, y: 6, w: 2, h: 2, i: '19' },
        ],
        draggable: true,
        resizable: true,
        responsive: true,
        index: 0,
      }
    },
  }
</script>

<style scoped>
  .vue-grid-layout {
    background: #eee;
  }

  .vue-grid-item:not(.vue-grid-placeholder) {
    background: #ccc;
    border: 1px solid black;
  }

  .vue-grid-item .resizing {
    opacity: 0.9;
  }

  .vue-grid-item .static {
    background: #cce;
  }

  .vue-grid-item .text {
    font-size: 24px;
    text-align: center;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
    height: 100%;
    width: 100%;
  }

  .vue-grid-item .no-drag {
    height: 100%;
    width: 100%;
  }

  .vue-grid-item .minMax {
    font-size: 12px;
  }

  .vue-grid-item .add {
    cursor: pointer;
  }

  .vue-draggable-handle {
    position: absolute;
    width: 20px;
    height: 20px;
    top: 0;
    left: 0;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'><circle cx='5' cy='5' r='5' fill='#999999'/></svg>")
      no-repeat;
    background-position: bottom right;
    padding: 0 8px 8px 0;
    background-repeat: no-repeat;
    background-origin: content-box;
    box-sizing: border-box;
    cursor: pointer;
  }

  .layoutJSON {
    background: #ddd;
    border: 1px solid black;
    margin-top: 10px;
    padding: 10px;
  }

  .columns {
    -moz-columns: 120px;
    -webkit-columns: 120px;
    columns: 120px;
  }
</style>

二、vue3使用(vue文件)

在vue3中如果報(bào)錯(cuò):

external_commonjs_vue_commonjs2_vue_root_Vue_default.a is not a constructor

1、需要導(dǎo)入vue3支持的該版本插件

npm add vue-grid-layout@3.0.0-beta1

2、在mian.js里引入:

import VueGridLayout from ‘vue-grid-layout'

加入:.use(VueGridLayout)
createApp(App).use(axios).use(router).use(VueGridLayout).mount(‘#app’)

因?yàn)関ue-grid-layout是vue2版本的 但自己用的是vue3版本,所以要安裝vue3的依賴和相關(guān)配置

三、在IE上無法打開,并報(bào)錯(cuò)缺少:

主要原因就是第三方庫的兼容性問題,把vue-grid-layout引入到vue.config.js文件下的transpileDependencies集合中:

module.exports = {
  ...
  transpileDependencies: ['element-ui', 'proxy-polyfill' , 'vue-grid-layout'],
}

總結(jié)

到此這篇關(guān)于前端開發(fā)指南之vue-grid-layout使用的文章就介紹到這了,更多相關(guān)vue-grid-layout使用實(shí)例內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue前端靈活改變后端地址兩種方式

    vue前端靈活改變后端地址兩種方式

    最近在學(xué)習(xí)或工作中遇到,把Vue前端項(xiàng)目打包后,要求可以再次修改請(qǐng)求后端接口的基礎(chǔ)地址,下面這篇文章主要給大家介紹了關(guān)于vue前端靈活改變后端地址的兩種方式,需要的朋友可以參考下
    2024-03-03
  • 使用Element的InfiniteScroll 無限滾動(dòng)組件報(bào)錯(cuò)的解決

    使用Element的InfiniteScroll 無限滾動(dòng)組件報(bào)錯(cuò)的解決

    這篇文章主要介紹了使用Element的InfiniteScroll 無限滾動(dòng)組件報(bào)錯(cuò)的解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • graphQL在前端vue中使用實(shí)例代碼

    graphQL在前端vue中使用實(shí)例代碼

    這篇文章主要介紹了graphQL在前端vue中使用過程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-03-03
  • vue中使用gantt-elastic實(shí)現(xiàn)可拖拽甘特圖的示例代碼

    vue中使用gantt-elastic實(shí)現(xiàn)可拖拽甘特圖的示例代碼

    這篇文章主要介紹了vue中使用gantt-elastic實(shí)現(xiàn)可拖拽甘特圖,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-07-07
  • 解決pycharm雙擊但是無法打開的情況

    解決pycharm雙擊但是無法打開的情況

    這篇文章主要介紹了解決pycharm雙擊但是無法打開的情況,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-10-10
  • Vue Element UI + OSS實(shí)現(xiàn)上傳文件功能

    Vue Element UI + OSS實(shí)現(xiàn)上傳文件功能

    這篇文章主要為大家詳細(xì)介紹了Vue Element UI + OSS實(shí)現(xiàn)上傳文件功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • 前端vue中實(shí)現(xiàn)文件下載的幾種方法總結(jié)

    前端vue中實(shí)現(xiàn)文件下載的幾種方法總結(jié)

    這篇文章主要介紹了前端vue中實(shí)現(xiàn)文件下載的幾種方法總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • vue項(xiàng)目配置env的方法步驟

    vue項(xiàng)目配置env的方法步驟

    在vue項(xiàng)目中env是全局配置文件,可以存儲(chǔ)不同環(huán)境下的變量,下面這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目配置env的方法步驟,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-04-04
  • Vue冷門技巧遞歸組件實(shí)踐示例詳解

    Vue冷門技巧遞歸組件實(shí)踐示例詳解

    這篇文章主要為大家介紹了Vue冷門技巧遞歸組件實(shí)踐示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03
  • Vue實(shí)現(xiàn)側(cè)邊菜單欄手風(fēng)琴效果實(shí)例代碼

    Vue實(shí)現(xiàn)側(cè)邊菜單欄手風(fēng)琴效果實(shí)例代碼

    本文通過一段簡(jiǎn)單的代碼給大家介紹了基于純vue實(shí)現(xiàn)側(cè)邊菜單欄手風(fēng)琴效果,代碼很簡(jiǎn)單,感興趣的朋友跟隨腳本之家小編一起看看吧
    2018-05-05

最新評(píng)論