vue項目回顧2【常用功能實現(xiàn)】

1.vue頁面中的css樣式

  <div class="my-list" id="my-list" :style="{'width':this.$store.state.width_s+'px'}">

也可以這樣寫:

<li @click="tabSwitch(1)" :class="{'active':activeId==1}">推薦</li>

以及

<div @click="switchSongShow()" :class="{'picturecon':true,'paused':!play.play}">

2.axios的用法
在mian.js中寫入:

import axios from 'axios'
Vue.prototype.$http = axios;

在當(dāng)前頁面引入

  import axios from 'axios'

get:

axios.get('/user?ID=12345')
    .then(function (response) {
        console.log(response);
    })
    .catch(function (error) {
        console.log(error);
    });

post:

axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
})
    .then(function (response) {
        console.log(response);
    })
    .catch(function (error) {
        console.log(error);
    });

3.手勢滑動的使用

html:
 <div class="songlist-row-s"  v-finger:swipe="swipeHandler">
js:
 swipeHandler(e){
          console.log("swipe" + e.direction);
        }

4.代參跳轉(zhuǎn)

html:
 <li v-for="(item,k) in songcollectList" @click="gofavoriteList(item)" v-if="k<6">
js:
      gofavoriteList(item_){
          //帶著id跳轉(zhuǎn)到favorite_list頁面
            this.$router.push({
              name: 'favorite_list',
              params: {
                id:item_
              }
            });
          }
or:
this.$router.push({path:'/favorite_list'});

favorite_list頁面:

beforeRouteEnter (to, from, next) {
          //跳轉(zhuǎn)到這個頁面后就被這個組件接受了
        next(vm => {
          var item_ = to.params.id;
    })
 },
也可以在methods的方法里面這樣取
  methods:{
          testFn(){
            var item_ = this.$route.query.id;
          }
}

5.頁面滾動監(jiān)聽

  mounted(){
          var tar = document.querySelector('.setting-index');
          var this_ = this;
          window.addEventListener('scroll',function () {
            console.dir(document.documentElement.scrollTop);
            if(document.documentElement.scrollTop == 160){
              this_.moreshow = false;
            }else{
              this_.moreshow = true;
            }
          });
      }

6.父組件向子組件傳數(shù)據(jù)
父組件:

<template>
    <div class="songPage-friend">
      <Songlistcommon :message="api"></Songlistcommon>
    </div>
</template>

<script>
    import Songlistcommon from './tool/songListcommon'
    export default {
        name: "song-page_friend",
        data(){
            return{
              api:'https://api.bzqll.com/music/tencent/search?offset=0&type=song'
            }
        },
      methods:{},
      components:{
        Songlistcommon
      }
    }
</script>

子組件:

   export default {
      props:['message'],
      name: "song-listcommon",
      data(){
        return{
          songlist:[]
        }
      },
      mounted(){
        var this_ = this;
        var api_ = this.message;
        axios.get(api_).then((res)=>{
          this_.songlist = res.data.data;
        });
      }

7.音頻播放

<audio v-show="false" id="audio" controls="controls" preload="auto" src="./../../static/myvideo.mp3"></audio>

var allProcess = document.getElementById('audio').duration;//音頻時長

8.后退

 this.$router.go(-1);

9.圖片引用

   <img :src="thissong.pic" alt="">

10.enter提交

 <input type="text" v-model="keyword" placeholder="你想搜的任何" @keyup.enter="submit()">

11.多組件引用

<Recommend></Recommend>
<Broad></Broad>
------------------------------------------------------------------------
 import Recommend from './songPage_recommend'
 import Broad from './songPage_broad'
-------------------------------------------------------------------------
 components:{
          Friend,Recommend,Broad,HeadNav
 }

12.引用公共js/css以及字體
在src/App.vue

import 'font-awesome/css/font-awesome.min.css'//引用字體
import './assets/css/common.css'//引用公共css

在main.js

import Common from './assets/js/common'
Vue.prototype.common = Common;//引用公共js

13.過濾filter

<span class="start">{{play.currentTime_|starttime('1',timer)}}</span>

   filters:{
        starttime(val,v1,v2){
          var currentTime_ = val;
       
        }
      }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容