iview按需引入

iview按需引入时报错

These dependencies were not found:

* iview/dist/styles/iview.css in ./src/main.js
* iview/src/components/button in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/HelloWorld.vue

To install them, you can run: npm install --save iview/dist/styles/iview.css iview/src/components/button

main.js

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import { Button } from 'iview'
import 'iview/dist/styles/iview.css'

Vue.config.productionTip = false
Vue.component('Button', Button)

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

.babelrc

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
      }
    }],
    "stage-2"
  ],
  "plugins": ["transform-vue-jsx", "transform-runtime", [
    "import", {
      "libraryName": "iview",
      "libraryDirectory": "src/components"
    }
  ]]
}

Hello.vue

<template>
  <div class="hello">
    <Button type="primary">Primary</Button>
  </div>
</template>
  • 我是按照最新的官方api来引入的,下面的插件已经引入了
npm install babel-plugin-import --save-dev

麻烦看下什么原因,谢谢~

阅读 4.3k
3 个回答

我这边自己弄好了,代码没问题,问题我没npm install iview,傻逼了,打扰各位。

clipboard.png

clipboard.png
import了button,没安装
一般直接import iView from 'iview';然后安装iview,它的组件全部都可用,不用一个一个引入

请问是使用iview cli安装的吗

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题