【问题标题】:Vuejs framework's elements not found未找到 Vuejs 框架的元素
【发布时间】:2018-08-12 13:19:16
【问题描述】:


我安装了名为 element 的 Vue.js 框架,但出现此错误。

我正在导入所有我需要的 index.html 和 Reviews.vue 文件,其中仅包含:

<template>
  <div id="app">
	<el-button type="primary" round>Primary</el-button>
  </div>
</template>

<script>
  import Vue from 'vue'
  import ColorPicker from 'element-ui'
  import 'element-ui/lib/theme-chalk/index.css'
  export default {}
</script>

<style lang="scss">

</style>
结果我得到的只是文本“Primary”

【问题讨论】:

    标签: javascript vue.js frontend element element-ui


    【解决方案1】:

    这个“快速入门”sn-p from the element github page 将引导您走向正确的方向:

    import Vue from 'vue'
    import Element from 'element-ui'
    
    Vue.use(Element)
    
    // or
    import {
      Select,
      Button
      // ...
    } from 'element-ui'
    
    Vue.component(Select.name, Select)
    Vue.component(Button.name, Button)
    

    基本上,您可以使用 Vue.use 语法加载所有元素(我相信这会将所有元素加载到您的包中,因此如果您不使用大量元素,您可能不想这样做您的应用程序中的组件),或者您在组件中加载元素的Button 组件:

    <template>
      <div id="app">
      <el-button type="primary" round>Primary</el-button>
      </div>
    </template>
    
    <script>
      import Vue from 'vue'
      import ColorPicker from 'element-ui'
      import 'element-ui/lib/theme-chalk/index.css'
      // mind this new line:
      import {Button} from 'element-ui'
      export default {}
    </script>
    
    <style lang="scss">
    
    </style>
    

    【讨论】:

      猜你喜欢
      • 2019-07-13
      • 2018-08-01
      • 2015-11-11
      • 2016-07-16
      • 2017-12-07
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多