微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

vue 组件中的 svg.js

如何解决vue 组件中的 svg.js

我在添加 SVG.js 库时遇到了一个大问题。就像我不做一样,我仍然画不出任何东西:(

我的文件: -public/index.html

<!DOCTYPE html>
<html lang="">
  <head>
    <Meta charset="utf-8">
    <Meta http-equiv="X-UA-Compatible" content="IE=edge">
    <Meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title><%= htmlWebpackPlugin.options.title %></title>

    <script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.js@3.0/dist/svg.min.js"></script>
  </head>
  <body style="font-size:11px">
    <noscript>
      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

-src/main.js

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import { SVG } from '@svgdotjs/svg.js'


import 'bootstrap/dist/css/bootstrap.min.css'
Vue.use(SVG);

Vue.config.productionTip = false

new Vue({
  router,SVG,render: h => h(App)
}).$mount('#app')

-src/components/picture.vue

<template>
<div class="row">
<div class="col-sm border-right" style="margin-right: 15px;background-color: #f3f3f3;">
</div>
<div class="col-auto" style="width: 703px;">
    <div class="row">
        <div class="col px-1 pt-1 pb-1">
            <div class="border row" style="width: 653px;height: calc(100vh - 61px);overflow: auto;">

                <div id="drawing">
                </div>
            </div>
        </div>
    </div>
</div>
<div class="col-sm border-left" style="margin-left: 15px; background-color: #f3f3f3;">

</div>
</div>
</template>

<script>
import axios from "axios";
import { SVG } from '@svgdotjs/svg.js'

export default {
    data() {
        return {

        }
    },created() {
        
            var draw = SVG().addTo('drawing').size(400,400) 
            var rect = draw.rect(100,100) 

    },methods: {

    }
}
</script>

我在页面上收到此错误

编译失败。

./src/components/Picture.vue 模块错误(来自 ./node_modules/eslint-loader/index.js):

D:\inzynierka\projekt\src\components\Picture.vue 41:17 错误 'rect' 被赋值但从未使用过 no-unused-vars

✖ 1 个问题(1 个错误,0 个警告)

解决方法

在代码中任何地方声明但未使用的变量很可能是由于重构不完整而导致的错误。此类变量会占用代码中的空间,并可能导致读者混淆。

var rect = draw.rect(100,100) 矩形未使用。

如果你想忽略它。你可以这样做

      // eslint-disable-next-line no-unused-vars
      var rect = draw.rect(100,100)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。