在pycharm中開發(fā)vue的方法步驟
一.在pycharm中開發(fā)vue
''' webstorm(vue) pycharm(python) goland(Go語言) 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)頁的圖標(biāo) -index.html 主頁面 -src:我們需要關(guān)注的 -assets:方靜態(tài)文件 -components:小組件 -views :頁面組件 -App.vue :主組件 -main.js :項(xiàng)目主入口js -router.js: 路由相關(guān),以后配置路由,都在這里配置 -store.js :vuex相關(guān),狀態(tài)管理器 -package.json 項(xiàng)目的依賴文件
三.每個(gè)vue組件由三部分組成
- template:放html代碼
- script:放js相關(guān)的東西
- style:放css相關(guān)
四.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語言']
}
}
}
六.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中通過$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)
})
-頁面掛載完成,執(zhí)行后面函數(shù),完成數(shù)據(jù)加載
mounted:function () {
this.init()
}
組件
<template>
<div class="course">
<h1>我是免費(fèi)課程頁面</h1>
<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ù)庫相關(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ù)庫中生成字段,只用于數(shù)據(jù)庫操作 policy = GenericRelation(to='PricePolicy')
-新建學(xué)位課程表的時(shí)候 DegreeCourse
# 不會(huì)在數(shù)據(jù)庫中生成字段,只用于數(shù)據(jù)庫操作 policy = GenericRelation(to='PricePolicy')
-價(jià)格策略表 PricePolicy
#之前有的字段該怎么寫就怎么寫 object_id = models.IntegerField() content_type = models.ForeignKey(to=ContenType,null=True) # 引入一個(gè)字段,不會(huì)在數(shù)據(jù)庫中創(chuàng)建,只用來做數(shù)據(jù)庫操作 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)
使用三:通過課程獲取價(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)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家
相關(guān)文章
快速解決vue動(dòng)態(tài)綁定多個(gè)class的官方實(shí)例語法無效的問題
今天小編就為大家分享一篇快速解決vue動(dòng)態(tài)綁定多個(gè)class的官方實(shí)例語法無效的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-09-09
elementui的table根據(jù)是否符合需求合并列的實(shí)現(xiàn)代碼
這篇文章主要介紹了elementui的table根據(jù)是否符合需求合并列的實(shí)現(xiàn)代碼,代碼簡單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-03-03
詳解element-ui日期時(shí)間選擇器的日期格式化問題
這篇文章主要介紹了詳解element-ui日期時(shí)間選擇器的日期格式化問題,本文用到了DateTimePicker來選擇日期時(shí)間,但是在將數(shù)據(jù)傳回后臺(tái)的過程中遇到了一些令人頭疼的問題,有興趣的一起來了解一下2019-04-04

