Skip to content

babel-plugin-import lead page error: Antd is not defined #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task
qifengwangye opened this issue Sep 17, 2018 · 6 comments
Closed
1 task

babel-plugin-import lead page error: Antd is not defined #193

qifengwangye opened this issue Sep 17, 2018 · 6 comments
Labels

Comments

@qifengwangye
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

1.1.1

Environment

ant-design-vue: 1.1.1; babel-plugin-import: 1.9.1; vue: 2.5.2

Reproduction link

https://git.coding.net/wangye84/vue-antd-admin-template.git

Steps to reproduce

when i import ant-design-vue and babel-plugin-import follow API guide's to :

// in main.js
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'
Vue.use(Antd)
// in .babelrc
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"stage-2"
],
"plugins": [
"transform-vue-jsx",
[
"import",
{
"libraryName": "ant-design-vue",
"libraryDirectory": "lib",
"style": true
}
],
"transform-runtime"
],
"env": {
"test": {
"presets": ["env"],
"plugins": [
"transform-vue-jsx",
"transform-es2015-modules-commonjs",
"dynamic-import-node",
"transform-runtime"
]
}
}
}

What is expected?

my web will be display

What is actually happening?

in browser's console, i saw the : Antd is not defined


branch : importAntd

@tangjinzhou
Copy link
Member

import Antd from 'ant-design-vue' and babel-plugin-import cannot be used together.
If you want to use babel-plugin-import, you should use it like this:
import { Button } from 'ant-design-vue'

@qifengwangye
Copy link
Author

@tangjinzhou And other question, if i use what you said's way, i will not declare antd in main.js ,right? so, i import component

in .vue file,like this:

<template>
<Menu
        theme="dark"
        mode="horizontal"
        :defaultSelectedKeys="['2']"
        :style="{ lineHeight: '64px' }"
      >
        <MenuItem key="1">nav 1</MenuItem>
      </Menu>
</template>
import {
  Menu
 } from 'ant-design-vue'
const { MenuItem } = Menu
<script>
   ...
   components: { Menu}
</script>

and other more ways to use Menu's compoenets like submenu and so on,
bu i got error reponse: Unknown custom element: <itemName> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
do you kown why and how to fix it?

@tangjinzhou
Copy link
Member

you should use it like this in main.js

import Vue from 'vue'
import { Button, message } from 'ant-design-vue'
import App from './App'

Vue.config.productionTip = false

Vue.component(Button.name, Button)
Vue.prototype.$message = message

/* eslint-disable no-new */
new Vue({
  el: '#app',
  components: { App },
  template: '<App/>'
})

More components in here

@qifengwangye
Copy link
Author

@tangjinzhou I just fixed this problem with import my component in .vue file and use const { Item } = Menu, I was do this but without statement it in components what leaded to up question

@tangjinzhou
Copy link
Member

https://github.com/vueComponent/ant-design-vue/blob/master/site/components.js#L109

@github-actions
Copy link

github-actions bot commented Apr 3, 2020

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants