鍍金池/ 問答/HTML/ iview按需引入

iview按需引入

iview按需引入時(shí)報(bào)錯(cuò)

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來引入的,下面的插件已經(jīng)引入了
npm install babel-plugin-import --save-dev

麻煩看下什么原因,謝謝~

回答
編輯回答
背叛者

clipboard.png

clipboard.png
import了button,沒安裝
一般直接import iView from 'iview';然后安裝iview,它的組件全部都可用,不用一個(gè)一個(gè)引入

2018年1月5日 20:49
編輯回答
掛念你

我這邊自己弄好了,代碼沒問題,問題我沒npm install iview,傻逼了,打擾各位。

2017年3月5日 08:04
編輯回答
過客

請(qǐng)問是使用iview cli安裝的嗎

2017年10月4日 03:51