''' webstorm(vue) pycharm(python) goland(Go語言) idea(java) andrioStuidio(安卓) Php(PHP) ''' ''' ①在pycharm中打開vue項目,在settins下Plugins中下載vue.js ②啟動vue項目 -方法1.在Terminal下輸入npm run serve -方法2.Edit Configurations----》點+ 選npm-----》在script對應的框中寫:serve '''
''' -node_modules:項目的依賴 -public -favicon.ico 網頁的圖標 -index.html 主頁面 -src:我們需要關注的 -assets:方靜態文件 -components:小組件 -views :頁面組件 -App.vue :主組件 -main.js :項目主入口js -router.js: 路由相關,以后配置路由,都在這里配置 -store.js :vuex相關,狀態管理器 -package.json 項目的依賴文件 '''
''' template:放html代碼 script:放js相關的東西 style:放css相關 '''
''' ①在src下views文件夾中創建一個組件 FreeCourse.vue ②配置路由 在src下router.js中配置 import FreeCourse from './views/FreeCourse.vue' { path: '/freecourse', name: 'freecourse', component: FreeCourse }, ③路由跳轉 在src下APP.vue中配置 <router-link to="/freecourse">免費課程</router-link> '''
''' ①在template中: <div class="course"> {{course_list}} </div> ②在script中: export default { name: 'course', data: function () { return{ course_list:['python','linux','go語言'] } } } '''
-安裝 npm install axios 在package.json文件中就能看到依賴 -在main.js中配置 //導入 axios import axios from 'axios' //把axios對象賦給$http Vue.prototype.$http=axios //以后在組件的js中通過$http取到的就是axios -在組件的js代碼中寫: this.$http.request({ //向下面的地址發送get請求 url:'http://127.0.0.1:8000/courses/', method:'get' }).then(function (response) { //response.data才是真正的數據 console.log(response.data) }) -頁面掛載完成,執行后面函數,完成數據加載 mounted:function () { this.init() } #組件 ''' <template> <div class="course"> <h1>我是免費課程頁面</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({ //向下面的地址發送get請求 url:'http://127.0.0.1:8000/courses/', method:'get' }).then(function (response) { //response.data才是真正的數據 _this.course_list = response.data }) } } , mounted:function () { this.init() } } </script> '''
-餓了么開源樣式 -安裝 npm i element-ui -S -在main.js中配置 import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; Vue.use(ElementUI); -去官方文檔看樣式完成復制粘貼 http://element-cn.eleme.io/#/zh-CN
什么時候使用? 實際項目中有一個表(PricePolicy)要關聯好幾個表(Course,DegreeCourse)也就是這個表要儲存好幾個表的數據,這種情況使用contentype組件 -新建免費課程表的時候 Course # 不會在數據庫中生成字段,只用於數據庫操作 policy = GenericRelation(to='PricePolicy') -新建學位課程表的時候 DegreeCourse # 不會在數據庫中生成字段,只用於數據庫操作 policy = GenericRelation(to='PricePolicy') -價格策略表 PricePolicy #之前有的字段該怎么寫就怎么寫 object_id = models.IntegerField() content_type = models.ForeignKey(to=ContenType,null=True) # 引入一個字段,不會在數據庫中創建,只用來做數據庫操作 content_obj = GenericForeignKey() 使用一(給課程添加價格策略): -給免費課django添加價格策略 course = models.Course.objects.get(pk=1) ret=models.PricePolicy.objects.create(period=30, price=199.9,content_obj=course) -給學位課程(python全棧開發)添加價格策略 degree_course = models.DegreeCourse.objects.get(pk=1) ret=models.PricePolicy.objects.create(period=30, price=199.9,content_obj=degree_course) 使用二:查詢價格策略對應的課程: price_policy=models.PricePolicy.objects.get(pk=1) print(price_policy.content_obj) 使用三:通過課程獲取價格策略 course = models.Course.objects.get(pk=1) policy_list=course.policy.all()