babel-plugin-component icon indicating copy to clipboard operation
babel-plugin-component copied to clipboard

Uncaught ReferenceError: _MessageBox is not defined

Open DotCoyote opened this issue 6 years ago • 8 comments

When using with babel@^7.0.0 everything works fine except of the MessageBox-Component of Vue elementUI:

Uncaught ReferenceError: _MessageBox is not defined

main.js:


/*
 * ELEMENT UI
 */
import {
  Alert,
  Button,
  ButtonGroup,
  Card,
  Checkbox,
  CheckboxGroup,
  Col,
  Collapse,
  CollapseItem,
  DatePicker,
  Dialog,
  Dropdown,
  DropdownItem,
  DropdownMenu,
  Form,
  FormItem,
  Input,
  Loading,
  MessageBox,
  Message,
  Option,
  Pagination,
  Radio,
  RadioGroup,
  Row,
  Select,
  Table,
  TableColumn,
  Tag,
  Tooltip,
  Tree,
  Upload
} from 'element-ui'
import lang from 'element-ui/lib/locale/lang/de'
import locale from 'element-ui/lib/locale'

// element-ui localization
locale.use(lang)

Vue.use(Alert)
Vue.use(Button)
Vue.use(ButtonGroup)
Vue.use(Card)
Vue.use(Checkbox)
Vue.use(CheckboxGroup)
Vue.use(Col)
Vue.use(Collapse)
Vue.use(CollapseItem)
Vue.use(DatePicker)
Vue.use(Dialog)
Vue.use(Dropdown)
Vue.use(DropdownItem)
Vue.use(DropdownMenu)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Input)
Vue.use(Loading)
Vue.use(Option)
Vue.use(Pagination)
Vue.use(Radio)
Vue.use(RadioGroup)
Vue.use(Row)
Vue.use(Select)
Vue.use(Tag)
Vue.use(Table)
Vue.use(TableColumn)
Vue.use(Tooltip)
Vue.use(Tree)
Vue.use(Upload)

Vue.prototype.$msgbox = MessageBox
Vue.prototype.$alert = MessageBox.alert
Vue.prototype.$confirm = MessageBox.confirm
Vue.prototype.$prompt = MessageBox.prompt
Vue.prototype.$message = Message

DotCoyote avatar Feb 22 '18 06:02 DotCoyote

同样遇到了这个问题

TrumanGu avatar Jul 09 '19 08:07 TrumanGu

mark

Yangfan2016 avatar Jul 16 '19 07:07 Yangfan2016

// TODO
// fix bug https://github.com/ElementUI/babel-plugin-component/issues/31
const _Loading = Loading
const { directive: loadingDirective, service: loadingService } = _Loading
const _MessageBox = MessageBox
const { alert, confirm, prompt } = _MessageBox

Vue.use(loadingDirective)

Vue.prototype.$loading = loadingService
Vue.prototype.$msgbox = _MessageBox
Vue.prototype.$alert = alert
Vue.prototype.$confirm = confirm
Vue.prototype.$prompt = prompt
Vue.prototype.$notify = Notification
Vue.prototype.$message = Message

UriChen avatar Sep 12 '19 15:09 UriChen

const { directive: loadingDirective, service: loadingService } = Loading
const msgbox = MessageBox
const { alert, confirm, prompt } = msgbox
Vue.use(loadingDirective)

Vue.prototype.$loading = loadingService
Vue.prototype.$msgbox = msgbox
Vue.prototype.$alert = alert
Vue.prototype.$confirm = confirm
Vue.prototype.$prompt = prompt
Vue.prototype.$notify = Notification
Vue.prototype.$message = Message

为啥这样写一下就行了。。感觉和直接用.是一样的

wzono avatar Nov 28 '19 09:11 wzono

const { directive: loadingDirective, service: loadingService } = Loading
const msgbox = MessageBox
const { alert, confirm, prompt } = msgbox
Vue.use(loadingDirective)

Vue.prototype.$loading = loadingService
Vue.prototype.$msgbox = msgbox
Vue.prototype.$alert = alert
Vue.prototype.$confirm = confirm
Vue.prototype.$prompt = prompt
Vue.prototype.$notify = Notification
Vue.prototype.$message = Message

为啥这样写一下就行了。。感觉和直接用。是一样的

我也还没弄明白,这个bug好像不是elementui导致的, 似乎是MessageBox的指向变成了_MessageBox导致无法被找到, 于是我就在本地声明一个变量来保存MessageBox,竟意外的解决了问题, 我发现在使用typescript时,除了MessageBox之外,Loading也存在bug,所以我过来更新了一下

UriChen avatar Jan 13 '20 15:01 UriChen

谢谢你的解惑,刚刚解决了_MessageBox这个问题, 另外loading的解决方案我觉得放在mixins里会更合适一点, 我现在没有触发到loading的这个bug

feimao90 avatar Mar 31 '20 04:03 feimao90

// TODO
// fix bug https://github.com/ElementUI/babel-plugin-component/issues/31
const _Loading = Loading
const { directive: loadingDirective, service: loadingService } = _Loading
const _MessageBox = MessageBox
const { alert, confirm, prompt } = _MessageBox

Vue.use(loadingDirective)

Vue.prototype.$loading = loadingService
Vue.prototype.$msgbox = _MessageBox
Vue.prototype.$alert = alert
Vue.prototype.$confirm = confirm
Vue.prototype.$prompt = prompt
Vue.prototype.$notify = Notification
Vue.prototype.$message = Message

为什么我按你的写了还是报_Loading找不到 image

itaffy avatar Sep 16 '20 02:09 itaffy

I have same problem, what cause this problem? because this plugin?

longshihui avatar Jun 23 '21 08:06 longshihui