简体   繁体   English

使用 vue-panzoom 组件时 vue3 未处理的错误

[英]vue3 unhandeled error when using vue-panzoom component

I used the panzoom in an older vue2 project.我在一个较旧的 vue2 项目中使用了 panzoom。

Now I tested the component in a simple vue3 setup and got "Unhandled error during execution of mounted hook at at "现在我在一个简单的 vue3 设置中测试了该组件,并得到了“在 at 处执行挂载的钩子时出现未处理的错误”

and "Cannot create panzoom for the current type of dom element"和“无法为当前类型的 dom 元素创建 panzoom”

where's the problem?问题出在哪里?

my package.json我的 package.json

{ "name": "image-zoom-test", "version": "0.1.0", "private": true, "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", "lint": "vue-cli-service lint" }, "dependencies": { "core-js": "^3.6.5", "vue": "^3.0.0", "vue-panzoom": "^1.1.6" }, "devDependencies": { "@vue/cli-plugin-babel": "~4.5.15", "@vue/cli-plugin-eslint": "~4.5.15", "@vue/cli-service": "~4.5.15", "@vue/compiler-sfc": "^3.0.0", "babel-eslint": "^10.1.0", "eslint": "^6.7.2", "eslint-plugin-vue": "^7.0.0" }, "eslintConfig": { "root": true, "env": { "node": true }, "extends": [ "plugin:vue/vue3-essential", "eslint:recommended" ], "parserOptions": { "parser": "babel-eslint" }, "rules": {} }, "browserslist": [ "> 1%", "last 2 versions", "not dead" ] } { "name": "image-zoom-test", "version": "0.1.0", "private": true, "scripts": { "serve": "vue-cli-service serve", "build" :“vue-cli-service build”,“lint”:“vue-cli-service lint”},“依赖项”:{“core-js”:“^3.6.5”,“vue”:“^3.0. 0", "vue-panzoom": "^1.1.6" }, "devDependencies": { "@vue/cli-plugin-babel": "~4.5.15", "@vue/cli-plugin-eslint" :“~4.5.15”,“@vue/cli-service”:“~4.5.15”,“@vue/compiler-sfc”:“^3.0.0”,“babel-eslint”:“^10.1. 0", "eslint": "^6.7.2", "eslint-plugin-vue": "^7.0.0" }, "eslintConfig": { "root": true, "env": { "node": true }, "extends": [ "plugin:vue/vue3-essential", "eslint:recommended" ], "parserOptions": { "parser": "babel-eslint" }, "rules": {} }, " browserslist": [ "> 1%", "last 2 versions", "not dead" ] }

main.js main.js

import { createApp } from 'vue'
import App from './App.vue'

const app = createApp(App)

// import vue-panzoom
import panZoom from 'vue-panzoom'

// install plugin
app.use(panZoom);

// createApp(App).mount('#app')
app.mount('#app')

and the vue file和vue文件

<template>
  <!-- <img alt="Vue logo" src="./assets/logo.png"> -->
  <!-- <HelloWorld msg="Welcome to Your Vue.js App"/> -->

        <!-- apply to an image -->
        <panZoom>
            <img src="https://picsum.photos/300">
        </panZoom>

        <!-- apply to regular dom elements -->
        <panZoom>
            <p>You can zoom me</p>
        </panZoom>

        <!-- apply to svg -->
        <panZoom selector="#g1">
            <svg height="210" width="400">
                <g id="g1">
                    <path d="M150 0 L75 200 L225 200 Z" />
                </g>
            </svg>
        </panZoom>

</template>

<script>


export default {
  name: 'App',
  components: {
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  margin-top: 0px;
  margin-left:0px;
  background-color: red;
  position : fixed;
  top: 0px;
  left:0px;
  width: 1920px;
  height: 1080px;
}
</style>

app id is mounted in main.js using app.mount('#app') app ID 使用app.mount('#app')安装在 main.js 中

But Div with id app is missing in the vue file.但是 vue 文件中缺少 ID 为app的 Div。

Vue file will look like following Vue 文件将如下所示

<template>
  <!-- <img alt="Vue logo" src="./assets/logo.png"> -->
  <!-- <HelloWorld msg="Welcome to Your Vue.js App"/> -->

       <!--missing div! -->
       <div id="app">

        <!-- apply to an image -->
        <panZoom>
            <img src="https://picsum.photos/300">
        </panZoom>

        <!-- apply to regular dom elements -->
        <panZoom>
            <p>You can zoom me</p>
        </panZoom>

        <!-- apply to svg -->
        <panZoom selector="#g1">
            <svg height="210" width="400">
                <g id="g1">
                    <path d="M150 0 L75 200 L225 200 Z" />
                </g>
            </svg>
        </panZoom>
       </div>
</template>

<script>


export default {
  name: 'App',
  components: {
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  margin-top: 0px;
  margin-left:0px;
  background-color: red;
  position : fixed;
  top: 0px;
  left:0px;
  width: 1920px;
  height: 1080px;
}
</style>

You can refer to official documentation of panzoom usage.可以参考panzoom使用的官方文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM