精品伊人久久大香线蕉,开心久久婷婷综合中文字幕,杏田冲梨,人妻无码aⅴ不卡中文字幕

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
vue-04

路由跳轉(zhuǎn)

this.$router.push('/course');this.$router.push({name: course});this.$router.go(-1);this.$router.go(1);<router-link to="/course">課程頁(yè)</router-link><router-link :to="{name: 'course'}">課程頁(yè)</router-link>

路由傳參

第一種

router.js
routes: [    // ...    {        path: '/course/:id/detail',        name: 'course-detail',        component: CourseDetail    },]
跳轉(zhuǎn).vue
<template>    <!-- 標(biāo)簽跳轉(zhuǎn) -->    <router-link :to="`/course/${course.id}/detail`">{{ course.name }}</router-link></template><script>    // ...    goDetail() {        // 邏輯跳轉(zhuǎn)        this.$router.push(`/course/${this.course.id}/detail`);    }</script>
接收.vue
created() {    let id = this.$route.params.id;}

第二種

router.js
routes: [    // ...    {        path: '/course/detail',        name: 'course-detail',        component: CourseDetail    },]
跳轉(zhuǎn).vue
<template>    <!-- 標(biāo)簽跳轉(zhuǎn) -->    <router-link :to="{            name: 'course-detail',            query: {id: course.id}        }">{{ course.name }}</router-link></template><script>    // ...    goDetail() {        // 邏輯跳轉(zhuǎn)        this.$router.push({            name: 'course-detail',            query: {                id: this.course.id            }        });    }</script>
接收.vue
created() {    let id = this.$route.query.id;}

可以完成跨組件傳參的四種方式

// 1) localStorage:永久存儲(chǔ)數(shù)據(jù)// 2) sessionStorage:臨時(shí)存儲(chǔ)數(shù)據(jù)(刷新頁(yè)面數(shù)據(jù)不重置,關(guān)閉再重新開啟標(biāo)簽頁(yè)數(shù)據(jù)重置)// 3) cookie:臨時(shí)或永久存儲(chǔ)數(shù)據(jù)(由過期時(shí)間決定)// 4) vuex的倉(cāng)庫(kù)(store.js):臨時(shí)存儲(chǔ)數(shù)據(jù)(刷新頁(yè)面數(shù)據(jù)重置)

vuex倉(cāng)庫(kù)插件

store.js配置文件
export default new Vuex.Store({    state: {        title: '默認(rèn)值'    },    mutations: {        // mutations 為 state 中的屬性提供setter方法        // setter方法名隨意,但是參數(shù)列表固定兩個(gè):state, newValue        setTitle(state, newValue) {            state.title = newValue;        }    },    actions: {}})
在任意組件中給倉(cāng)庫(kù)變量賦值
this.$store.state.title = 'newTitle'this.$store.commit('setTitle', 'newTitle')
在任意組件中取倉(cāng)庫(kù)變量的值
console.log(this.$store.state.title)

vue-cookie插件

安裝
>: cnpm install vue-cookies
main.js 配置
// 第一種import cookies from 'vue-cookies'   // 導(dǎo)入插件Vue.use(cookies);                   // 加載插件new Vue({    // ...    cookies,                        // 配置使用插件原型 $cookies}).$mount('#app');// 第二種import cookies from 'vue-cookies'   // 導(dǎo)入插件Vue.prototype.$cookies = cookies;   // 直接配置插件原型 $cookies
使用
// 增(改): key,value,exp(過期時(shí)間)// 1 = '1s' | '1m' | '1h' | '1d'this.$cookies.set('token', token, '1y');// 查:keythis.token = this.$cookies.get('token');// 刪:keythis.$cookies.remove('token');
注:cookie一般都是用來存儲(chǔ)token的
// 1) 什么是token:安全認(rèn)證的字符串// 2) 誰(shuí)產(chǎn)生的:后臺(tái)產(chǎn)生// 3) 誰(shuí)來存儲(chǔ):后臺(tái)存儲(chǔ)(session表、文件、內(nèi)存緩存),前臺(tái)存儲(chǔ)(cookie)// 4) 如何使用:服務(wù)器先生成反饋給前臺(tái)(登陸認(rèn)證過程),前臺(tái)提交給后臺(tái)完成認(rèn)證(需要登錄后的請(qǐng)求)// 5) 前后臺(tái)分離項(xiàng)目:后臺(tái)生成token,返回給前臺(tái) => 前臺(tái)自己存儲(chǔ),發(fā)送攜帶token請(qǐng)求 => 后臺(tái)完成token校驗(yàn) => 后臺(tái)得到登陸用戶

axios插件

安裝
>: cnpm install axios
main.js配置
import axios from 'axios'   // 導(dǎo)入插件Vue.prototype.$axios = axios;   // 直接配置插件原型 $axios
使用
this.axios({    url: '請(qǐng)求接口',    method: 'get|post請(qǐng)求',    data: {post等提交的數(shù)據(jù)},    params: {get提交的數(shù)據(jù)}}).then(請(qǐng)求成功的回調(diào)函數(shù)).catch(請(qǐng)求失敗的回調(diào)函數(shù))
案例
// get請(qǐng)求this.$axios({    url: 'http://127.0.0.1:8000/test/ajax/',    method: 'get',    params: {        username: this.username    }}).then(function (response) {    console.log(response)}).catch(function (error) {    console.log(error)});// post請(qǐng)求this.$axios({    url: 'http://127.0.0.1:8000/test/ajax/',    method: 'post',    data: {        username: this.username    }}).then(function (response) {    console.log(response)}).catch(function (error) {    console.log(error)});

跨域問題(同源策略)

// 后臺(tái)接收到前臺(tái)的請(qǐng)求,可以接收前臺(tái)數(shù)據(jù)與請(qǐng)求信息,發(fā)現(xiàn)請(qǐng)求的信息不是自身服務(wù)器發(fā)來的請(qǐng)求,拒絕響應(yīng)數(shù)據(jù),這種情況稱之為 - 跨域問題(同源策略 CORS)// 導(dǎo)致跨域情況有三種// 1) 端口不一致// 2) IP不一致// 3) 協(xié)議不一致// Django如何解決 - django-cors-headers模塊// 1) 安裝:pip3 install django-cors-headers// 2) 注冊(cè):INSTALLED_APPS = [    ...    'corsheaders']// 3) 設(shè)置中間件:MIDDLEWARE = [    ...    'corsheaders.middleware.CorsMiddleware']// 4) 設(shè)置跨域:CORS_ORIGIN_ALLOW_ALL = True

element-ui插件

安裝
>: cnpm i element-ui -S
main.js配置
import ElementUI from 'element-ui';import 'element-ui/lib/theme-chalk/index.css';Vue.use(ElementUI);
使用
依照官網(wǎng) https://element.eleme.cn/#/zh-CN/component/installation api


本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
記一次Vue Hybrid App(混合APP)開發(fā)
手摸手,帶你用vue擼后臺(tái) 系列四(vueAdmin 一個(gè)極簡(jiǎn)的后臺(tái)基礎(chǔ)模板)
使用Vue,Spring Boot,Flask,Django 完成Vue前后端分離開發(fā)
Vue 中 Axios 的封裝和 API 接口的管理
webpack-cdn
vue項(xiàng)目實(shí)戰(zhàn)經(jīng)驗(yàn)匯總
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

主站蜘蛛池模板: 宁化县| 江孜县| 城口县| 彭州市| 遂宁市| 渑池县| 丰县| 舞钢市| 广宗县| 响水县| 随州市| 休宁县| 达州市| 康马县| 岑溪市| 逊克县| 东乌珠穆沁旗| 齐河县| 吉木乃县| 铜川市| 万宁市| 额敏县| 浦城县| 盱眙县| 南郑县| 平度市| 南昌市| 新兴县| 喀什市| 关岭| 罗城| 平阳县| 万源市| 马尔康县| 封开县| 固原市| 江都市| 鞍山市| 南城县| 平武县| 宜州市|