一.在pycharm中開發(fā)vue
成都創(chuàng)新互聯(lián)公司主營(yíng)金東網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都App定制開發(fā),金東h5小程序制作搭建,金東網(wǎng)站營(yíng)銷推廣歡迎金東等地區(qū)企業(yè)咨詢
''' webstorm(vue) pycharm(python) goland(Go語(yǔ)言) idea(java) andrioStuidio(安卓) Php(PHP) ''' ''' ①在pycharm中打開vue項(xiàng)目,在settins下Plugins中下載vue.js ②啟動(dòng)vue項(xiàng)目 -方法1.在Terminal下輸入npm run serve -方法2.Edit Configurations----》點(diǎn)+ 選npm-----》在script對(duì)應(yīng)的框中寫:serve '''
二.vue項(xiàng)目的目錄結(jié)構(gòu)
-node_modules:項(xiàng)目的依賴 -public -favicon.ico 網(wǎng)頁(yè)的圖標(biāo) -index.html 主頁(yè)面 -src:我們需要關(guān)注的 -assets:方靜態(tài)文件 -components:小組件 -views :頁(yè)面組件 -App.vue :主組件 -main.js :項(xiàng)目主入口js -router.js: 路由相關(guān),以后配置路由,都在這里配置 -store.js :vuex相關(guān),狀態(tài)管理器 -package.json 項(xiàng)目的依賴文件
三.每個(gè)vue組件由三部分組成
四.vue中路由的創(chuàng)建
①在src下views文件夾中創(chuàng)建一個(gè)組件 FreeCourse.vue
②配置路由
在src下router.js中配置
import FreeCourse from './views/FreeCourse.vue' { path: '/freecourse', name: 'freecourse', component: FreeCourse },
③路由跳轉(zhuǎn)
在src下APP.vue中配置
<router-link to="/freecourse">免費(fèi)課程</router-link>
五.在組件中顯示數(shù)據(jù)
①在template中:
<div class="course"> {{course_list}} </div>
②在script中:
export default { name: 'course', data: function () { return{ course_list:['python','linux','go語(yǔ)言'] } } }
六.vue中的axios完成前后臺(tái)交互
-安裝
npm install axios 在package.json文件中就能看到依賴
-在main.js中配置
//導(dǎo)入 axios import axios from 'axios' //把a(bǔ)xios對(duì)象賦給$http Vue.prototype.$http=axios //以后在組件的js中通過(guò)$http取到的就是axios
-在組件的js代碼中寫:
this.$http.request({ //向下面的地址發(fā)送get請(qǐng)求 url:'http://127.0.0.1:8000/courses/', method:'get' }).then(function (response) { //response.data才是真正的數(shù)據(jù) console.log(response.data) })
-頁(yè)面掛載完成,執(zhí)行后面函數(shù),完成數(shù)據(jù)加載
mounted:function () { this.init() }
組件
<template> <div class="course"> <h2>我是免費(fèi)課程頁(yè)面</h2> <p v-for="course in course_list">{{course}}</p> </div> </template> <script> export default { name: 'course', data: function () { return{ course_list:[] } }, methods: { 'init':function () { var _this = this; this.$http.request({ //向下面的地址發(fā)送get請(qǐng)求 url:'http://127.0.0.1:8000/courses/', method:'get' }).then(function (response) { //response.data才是真正的數(shù)據(jù) _this.course_list = response.data }) } } , mounted:function () { this.init() } } </script>
七.vue中使用element-ui
-餓了么開源樣式
-安裝 npm i element-ui -S
-在main.js中配置
import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; Vue.use(ElementUI);
-去官方文檔看樣式完成復(fù)制粘貼 http://element-cn.eleme.io/#/zh-CN
八.contentype組件(數(shù)據(jù)庫(kù)相關(guān))
什么時(shí)候使用?
實(shí)際項(xiàng)目中有一個(gè)表(PricePolicy)要關(guān)聯(lián)好幾個(gè)表(Course,DegreeCourse)也就是這個(gè)表要儲(chǔ)存好幾個(gè)表的數(shù)據(jù),這種情況使用contentype組件
-新建免費(fèi)課程表的時(shí)候 Course
# 不會(huì)在數(shù)據(jù)庫(kù)中生成字段,只用于數(shù)據(jù)庫(kù)操作 policy = GenericRelation(to='PricePolicy')
-新建學(xué)位課程表的時(shí)候 DegreeCourse
# 不會(huì)在數(shù)據(jù)庫(kù)中生成字段,只用于數(shù)據(jù)庫(kù)操作 policy = GenericRelation(to='PricePolicy')
-價(jià)格策略表 PricePolicy
#之前有的字段該怎么寫就怎么寫 object_id = models.IntegerField() content_type = models.ForeignKey(to=ContenType,null=True) # 引入一個(gè)字段,不會(huì)在數(shù)據(jù)庫(kù)中創(chuàng)建,只用來(lái)做數(shù)據(jù)庫(kù)操作 content_obj = GenericForeignKey()
使用一(給課程添加價(jià)格策略):
-給免費(fèi)課django添加價(jià)格策略
course = models.Course.objects.get(pk=1) ret=models.PricePolicy.objects.create(period=30, price=199.9,content_obj=course)
-給學(xué)位課程(python全棧開發(fā))添加價(jià)格策略
degree_course = models.DegreeCourse.objects.get(pk=1) ret=models.PricePolicy.objects.create(period=30, price=199.9,content_obj=degree_course)
使用二:查詢價(jià)格策略對(duì)應(yīng)的課程:
price_policy=models.PricePolicy.objects.get(pk=1) print(price_policy.content_obj)
使用三:通過(guò)課程獲取價(jià)格策略
course = models.Course.objects.get(pk=1) policy_list=course.policy.all()
到此這篇關(guān)于在pycharm中開發(fā)vue的方法步驟的文章就介紹到這了,更多相關(guān)pycharm開發(fā)vue內(nèi)容請(qǐng)搜索創(chuàng)新互聯(lián)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持創(chuàng)新互聯(lián)
當(dāng)前標(biāo)題:在pycharm中開發(fā)vue的方法步驟
文章分享:http://bm7419.com/article10/gijpdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、做網(wǎng)站、網(wǎng)站營(yíng)銷、用戶體驗(yàn)、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)