使用webpack+vue-cli構建專案
阿新 • • 發佈:2019-01-06
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>