全局安装vue-cli(3.0版本) $ npm install -g @vue/cli # 建立一个新项目 $ vue create my-project # 进入项目 $ cd my-project # 安装依赖 $ npm install # 启动项目 $ npm run serve
建立项目时的具体配置可参考:vue脚手架3.0的使用html
建立完成:vue
$ npm install --save-dev less less-loader
使用方式webpack
<style lang="less"> @import "./assets/common.less"; </style>
<style lang="less"> #app { font-family: 'Avenir', Helvetica, Arial, sans-serif; color: #2c3e50; margin-top: 60px; } </style>
webstorm编辑器,页面中的less文件会提示错误,添加rel="stylesheet/less"属性ios
<style scoped lang="less" rel="stylesheet/less"></style>
根目录.editorconfig文件git
indent_size = 4
webpack.base.conf.js文件设置,把下面这段注释掉就行了github
const createLintingRule = () => ({ // test: /\.(js|vue)$/, // loader: 'eslint-loader', // enforce: 'pre', // include: [resolve('src'), resolve('test')], // options: { // formatter: require('eslint-friendly-formatter'), // emitWarning: !config.dev.showEslintErrorsInOverlay // } })
文档地址: https://github.com/axios/axios
npm install --save-dev axios
axios.get('/user', { params: { ID: 12345 } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
buile//webpack配置信息 src//开发环境内容 --components//vue组件 --router --index.js//路由配置信息 --App.vue//入口html页面 --main.js//入口页面 static//打包后内容
在components文件夹下新建Index.vue,页面内容以下web
<template> <div class="hello"> <h1>{{ msg }}</h1> <h2>Essential Links</h2> </div> </template> <script> export default { name: 'Index',//须要与路由配置的name统一 data () { return { msg: 'Welcome to Your Vue.js App' } } } </script> <style scoped lang="less" rel="stylesheet/less"> </style>
在router/index.js页面添加以下内容vue-cli
import Index from '@/components/Index'
{ path: '/', name: 'Index', component: Index },
官方文档
无需安装,直接使用,在第一步安装完成时已经生成store.js文件npm