美文网首页
Vue中使用SVG作为边框

Vue中使用SVG作为边框

作者: shine大臣 | 来源:发表于2020-09-06 13:38 被阅读0次

首先我们看下目录结构

image.png

1、定义borderBox组件

<template>
  <div class="borderBox110">
    <svg class="borderBox" width="374" height="226" xmlns="http://www.w3.org/2000/svg">
      <g>
        <title>background</title>
        <rect fill="#fff" id="canvas_background" height="228" width="376" y="-1" x="-1"/>
        <g display="none" overflow="visible" y="0" x="0" height="100%" width="100%" id="canvasGrid">
          <rect fill="url(#gridpattern)" stroke-width="0" y="0" x="0" height="100%" width="100%"/>
        </g>
      </g>
      <g>
        <title>Layer 1</title>
        <rect id="svg_1" height="190" width="372" y="0.749997" x="0.75" stroke-width="1.5" stroke="#000" fill="#fff"/>
        <rect id="svg_2" height="3" width="2" y="81.749997" x="100.75" stroke-width="1.5" stroke="#000" fill="#fff"/>
        <rect id="svg_3" height="188" width="347" y="17.749997" x="12.75" stroke-width="1.5" stroke="#000" fill="#fff"/>
        <rect id="svg_4" height="193" width="320" y="31.749997" x="29.75" fill-opacity="null" stroke-opacity="null"
              stroke-width="1.5" stroke="#000" fill="#fff"/>
      </g>
    </svg>
    <div class="content">
      <slot></slot>
    </div>
  </div>

</template>

<script>
export default {
  name: "borderBox110"
}
</script>

<style lang="scss" scoped>
.borderBox110 {
  position: relative;

  .borderBox {
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
  }
  .content{
    position: absolute;
    left: 0;
    top: 0;
  }

}
</style>

2、全局注册组件

  • 1、新建一个index.js文件
import borderBox110 from "./borderBox110";

// 这里是重点
export default function (Vue) {
    Vue.component(borderBox110.name, borderBox110)
}
  • 2、在外部同样定义一个index.js文件,用来全局注册
import Vue from 'vue'

import borderBox110 from "@/components/borderBox/borderBox1/index";

Vue.use(borderBox110)

  • 2、在main.js中引入刚才新建的index.js文件
import './components/borderBox/index'

3、使用
在其他组件中我们可以直接使用<borderBox110></borderBox110>便签即可

 <borderBox110 class="borderBox">
    <p class="test">
      测试
    </p>
  </borderBox110>

4、显示


image.png

相关文章

  • Vue中使用SVG作为边框

    首先我们看下目录结构 1、定义borderBox组件 2、全局注册组件 1、新建一个index.js文件 2、在外...

  • 插件工具 | 在vue中引入svg图标

    前言 1、基于 vue-cli32、使用插件 svg-sprite-loader 在 src/icons/svg文...

  • 项目使用svg图标

    vue-element-admin基础模板中,已经封装好了使用svg图标的组件,此组件在vue-ssr项目中也同样...

  • vue中使用svg注意点

    网上介绍在vue中如何使用svg的教程已经很多了,我这不多做赘述。 场景 已经根据网上的教程,将svg组件引入到页...

  • Vue React大屏数据展示组件库 类似阿里DataV

    Vue/React版本数据可视化组件库(类似阿里DataV,大屏数据展示),提供SVG的边框及装饰、图表、水位图、...

  • vue使用svg

    vue使用svg 做的一个可视化大屏项目中需要引入svg, 直接绑定svg元素的某些值,在ui给的svg中出现了s...

  • vue 使用 svg

    说明:很多关于类似的博客或者文档介绍的第三方库,由于有文件目录配置单一或者有webpack 兼容问题,所以都不考虑...

  • vue使用svg

    友情链接:https://www.jianshu.com/p/15f9e3a5e00d 终端安装 npm npm ...

  • vue使用svg

    在vue中使用svg svg的好处矢量性(无论图片放多大,都不会出现锯齿状模糊)利于seo 1. 安装依赖 2. ...

  • vue 使用svg

网友评论

      本文标题:Vue中使用SVG作为边框

      本文链接:https://www.haomeiwen.com/subject/oevkektx.html