美文网首页前端碎碎念
vant按需自动引入使用标签时报错

vant按需自动引入使用标签时报错

作者: const_express | 来源:发表于2021-04-11 23:22 被阅读0次
Unknown custom element: <van-tag> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

这个是报的错,说我没注册我:?????
搞半天不知道怎么弄,翻阅了一下官网,我采用的是推荐使用的按需自动引入
先贴上来:

// 在.babelrc 中添加配置
// 注意:webpack 1 无需设置 libraryDirectory
{
  "plugins": [
    ["import", {
      "libraryName": "vant",
      "libraryDirectory": "es",
      "style": true
    }]
  ]
}

// 对于使用 babel7 的用户,可以在 babel.config.js 中配置
module.exports = {
  plugins: [
    ['import', {
      libraryName: 'vant',
      libraryDirectory: 'es',
      style: true
    }, 'vant']
  ]
};

本来以为这样就可以万事大吉了,然鹅并不是.我想使用标签组件的时候
我在template中直接复制

<van-tag v-if="show" closeable size="medium" type="primary" @close="close">
  标签
</van-tag>

竟然报错了......无语子
后来发现必须要在下面组件中写这样一个

 import {
        testLogin
    } from '@/request/api.js'
    import {
        Tag
    } from 'vant';
    export default {
        name: 'index',
        components: {
            [Tag.name]: Tag
        },
}

才不报错了....踩坑+1

相关文章

网友评论

    本文标题:vant按需自动引入使用标签时报错

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