1、首先安装好node环境,然后再项目文件夹根目录下执行命令安装vue相关功能
npm install -g @vue/cli-init
2、初始化项目
vue init webpack project(你新建的项目名称/文件名称)
3、使用命令cd project 转到项目目录下npm install, 下载依赖安装,然后运行项目
cd project
npm install
npm run dev
4、如果与后端对接数据需要安装vue-resource
npm install vue-resource --save
5、然后再项目中main.js中引用
import VueResource from 'vue-resource'
Vue.use(VueResource)
Vue.http.options.root='全局配置的url'
6、再组件中获取数据,不需要加“/”
<script>
export default {
name: 'HelloWorld',
data () {
return {
msg: ''
}
},
created(){
this.getlist();
},
methods:{
getlist(){
this.$http.get('cities?type=guess').then(response => {
this.msg=response.body.name
}, response => {
this.msg="获取数据失败"
});
}
}
}
</script>