overtrue / vue-avatar-cropper

:girl: A simple and elegant avatar cropping and upload plugin.
https://github.com/overtrue/vue-avatar-cropper
513 stars 93 forks source link

用cdn引用报错 #334

Closed gaolin16 closed 3 years ago

gaolin16 commented 3 years ago

我想用cdn的方式引用

但是使用标签时报错: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.

overtrue commented 3 years ago

麻烦贴出你的代码

gaolin16 commented 3 years ago

麻烦贴出你的代码

您好,控件很简洁,十分想用,我是用cdn方式使用vue,element组件就是这么使用的,代码如下,在body里id为app的div里:

< div class="text-center">
< img v-if="userAvatar" :src="userAvatar">
    < button id="pick-avatar">选择一张图片</button>
    < avatar-cropper
      @uploaded="handleUploaded"
      trigger="#pick-avatar"
      upload-url="/files/upload" />
  < /div>
< /div>

以下是html结束后的引用代码:

<script src="/element/vue.js"></script>
<script src="/element/index.js"></script>
<script src="/component/node_modules/vue-avatar-cropper/dist/index.js"></script>
<script>
  data.userAvatar="";
  methods.handleUploaded=function(resp) {
    this.userAvatar = resp.relative_url;
  }
  const mainVue = new Vue({
    el: '#app',
    data: data,
    methods: methods,
  });
</script>

尝试了多种写法,都没成功,包括使用Vue.use,element组件是可以正常使用的。现在console里报错:Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.

用cdn的方式,使用cropperjs也是可以的,但avatar-cropper不行,麻烦您指点一下,谢谢。

gaolin16 commented 3 years ago

您好,Gitthub上代码不换行,我用邮件给您发一下试试。我用element的控件组用这种方式一直没有问题,引用您的控件时报错。

您写的这个控件真的特别简洁,我特别喜欢,我用的是cdn的方式引用vue,代码如下:

<html> <head> <script> var data={};

var methods={}; </head>

<body> <div id="app">

<div class="text-center">     <img v-if="userAvatar" :src="userAvatar">     <button id="pick-avatar">选择一张图片</button>     <avatar-cropper       @uploaded="handleUploaded"       trigger="#pick-avatar"       upload-url="/files/upload" /> </div>

</div> </body> </html>

<script src="/element/vue.js"></script> <script src="/element/index.js"></script> <script src="/component/node_modules/vue-avatar-cropper/dist/index.js"></script> <script> data.userAvatar=""; methods.handleUploaded=function(resp) { this.userAvatar = resp.relative_url; };

  const mainVue = new Vue({     el: '#app',     data: data,     methods: methods,   }); </script>

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2021年3月12日(星期五) 上午10:16 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [overtrue/vue-avatar-cropper] 用cdn引用报错 (#334)

麻烦贴出你的代码

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

overtrue commented 3 years ago

花5分钟了解一下 markdown

overtrue commented 3 years ago

你需要在 new Vue 的时候注册 components 啊