創(chuàng)建Vue項目以及引入Iview的方法示例
創(chuàng)建Vue項目 以及引入Iview
# 全局安裝 vue-cli $ npm install --global vue-cli # 創(chuàng)建一個基于 webpack 模板的新項目 $ vue init webpack my-project # 安裝依賴,走你 $ cd my-project $ npm install $ npm run dev
以上是vue官方文檔中Vue.js 提供一個 官方命令行工具 創(chuàng)建vue項目的方法。
我創(chuàng)建Vue項目過程
$ vue init webpack vue-iview
? Project name vue-iview ? Project description A Vue.js project ? Author yourname <youremail@example.com> ? Vue build standalone ? Install vue-router? Yes ? Use ESLint to lint your code? Yes ? Pick an ESLint preset Standard ? Setup unit tests with Karma + Mocha? Yes ? Setup e2e tests with Nightwatch? Yes vue-cli · Generated "vue-iview". To get started: cd vue-iview npm install npm run dev Documentation can be found at https://vuejs-templates.github.io/webpack
$ cd vue-iview/ $ cnpm install $ npm run dev
vue init webpack vue-iview 時我使用默認(rèn)的選項,直接回車;這里使用cnpm 安裝依賴
引入iview
src/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 iView from 'iview'
import 'iview/dist/styles/iview.css' // 使用 CSS
Vue.config.productionTip = false
Vue.use(iView)
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
})
在main.js中添加了
import iView from 'iview' import 'iview/dist/styles/iview.css' // 使用 CSS Vue.use(iView)
以上3行代碼
iview 安裝
$ cnpm install --save iview
使用iview 組件
創(chuàng)建 src/components/LoginForm.vue
官方的組件代碼縮進不符合要求,需要修改
<template>
<Form ref="formInline" :model="formInline" :rules="ruleInline" inline>
<FormItem prop="user">
<Input type="text" v-model="formInline.user" placeholder="Username">
<Icon type="ios-person-outline" slot="prepend"></Icon>
</Input>
</FormItem>
<FormItem prop="password">
<Input type="password" v-model="formInline.password" placeholder="Password">
<Icon type="ios-locked-outline" slot="prepend"></Icon>
</Input>
</FormItem>
<FormItem>
<Button type="primary" @click="handleSubmit('formInline')">登錄</Button>
</FormItem>
</Form>
</template>
<script>
export default {
data () {
return {
formInline: {
user: '',
password: ''
},
ruleInline: {
user: [
{ required: true, message: '請?zhí)顚懹脩裘?, trigger: 'blur' }
],
password: [
{ required: true, message: '請?zhí)顚懨艽a', trigger: 'blur' },
{ type: 'string', min: 6, message: '密碼長度不能小于6位', trigger: 'blur' }
]
}
}
},
methods: {
handleSubmit (name) {
this.$refs[name].validate((valid) => {
if (valid) {
this.$Message.success('提交成功!')
} else {
this.$Message.error('表單驗證失敗!')
}
})
}
}
}
</script>
src/App.vue:
<template>
<div id="app">
<LoginForm></LoginForm>
</div>
</template>
<script>
import LoginForm from './components/LoginForm'
export default {
name: 'app',
components: {
'LoginForm': LoginForm
}
}
</script>
<style>
#app {
}
</style>
補充:vue安裝完iview后,啟動項目,提示 in ./node_modules/dist/styles/iview.css 報錯
打開 webpack.base.conf.js,找到 test:/.css$/,添加includ項即可
{
test:/\.css$/,
loader:'style-loader!css-loader!stylus-loader',
include:[
/src/,
'/node_modules/iview/dist/styles/iview.css'
]
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue項目報錯Uncaught runtime errors的解決方案
使用vue-cli的vue項目,出現(xiàn)編譯錯誤或警告時,在瀏覽器中顯示全屏覆蓋,提示報錯Uncaught runtime errors,本文給大家介紹了vue項目報錯Uncaught runtime errors的解決方案,需要的朋友可以參考下2024-01-01
Vue3?watchEffect的使用教程和相關(guān)概念
Vue?3?引入了?Composition?API,其中?watchEffect?是一個非常強大的工具,用于響應(yīng)式地追蹤依賴項的變化,本文將詳細(xì)介紹?watchEffect?的使用方法和相關(guān)概念,文中有詳細(xì)的代碼供大家參考,需要的朋友可以參考下2024-08-08
Element控件Tree實現(xiàn)數(shù)據(jù)樹形結(jié)構(gòu)的示例代碼
我們在開發(fā)中肯定會遇到用樹形展示數(shù)據(jù)的需求,本文主要介紹了Element控件Tree實現(xiàn)數(shù)據(jù)樹形結(jié)構(gòu)的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-08-08
html+vue.js 實現(xiàn)漂亮分頁功能可兼容IE
功能比較簡單,在單一html中使用vue.js分頁展示數(shù)據(jù),并未安裝腳手架,或使用相關(guān)UI框架,此時需要手寫一個分頁器,不失為最合理最便捷的解決方案,需要的朋友可以參考下2020-11-11
elementUI樣式修改未生效問題詳解(掛載到了body標(biāo)簽上)
vue+elementUI項目開發(fā)中,經(jīng)常遇到修改elementUI組件樣式無效的問題,這篇文章主要給大家介紹了關(guān)于elementUI樣式修改未生效問題的相關(guān)資料,掛載到了body標(biāo)簽上,需要的朋友可以參考下2023-04-04
vue-cli中的babel配置文件.babelrc實例詳解
Babel是一個廣泛使用的轉(zhuǎn)碼器,可以將ES6代碼轉(zhuǎn)為ES5代碼,從而在現(xiàn)有環(huán)境執(zhí)行。本文介紹vue-cli腳手架工具根目錄的babelrc配置文件,感興趣的朋友一起看看吧2018-02-02

