欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

在pycharm中開(kāi)發(fā)vue的方法步驟

 更新時(shí)間:2020年03月04日 10:42:01   作者:Zhuang_Z  
這篇文章主要介紹了在pycharm中開(kāi)發(fā)vue的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

一.在pycharm中開(kāi)發(fā)vue

'''
webstorm(vue) pycharm(python) goland(Go語(yǔ)言) idea(java) andrioStuidio(安卓) Php(PHP)
'''

'''
①在pycharm中打開(kāi)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組件由三部分組成

  • 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語(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">
  <h1>我是免費(fèi)課程頁(yè)面</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

-餓了么開(kāi)源樣式

-安裝 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全棧開(kāi)發(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中開(kāi)發(fā)vue的方法步驟的文章就介紹到這了,更多相關(guān)pycharm開(kāi)發(fā)vue內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家

相關(guān)文章

最新評(píng)論