老师啊!!我点击搜索框报错了

老师啊!!我点击搜索框报错了

header.vue

<template>

    <navbar class="header" 

    :class="{'header-transition': isHeaderTransition}"

    v-show="visible"

    >

        <i class="iconfont icon-scan" slot="left"></i>

        <me-search-box slot="center" @click.native="goToSearch" fake></me-search-box>

        <i class="iconfont icon-msg" slot="right"></i>

    </navbar>

</template>


<script>

import Navbar from 'base/navbar'

import MeSearchBox from 'base/search-box'


export default {

    name: "HomeHeader",

    props: {

        isHeaderTransition: {

            type: Boolean,

            default: false

        }

    },

    data() {

        return {

            visible: true

        }

    },

    components: {

        Navbar,

        MeSearchBox

    },

    methods: {

        show() {

            this.visible = true

        },

        hide() {

            this.visible = false

        },

        goToSearch() {

            this.$router.push('/search');

        }

    }

}

</script>


<style lang="scss" scoped>

@import "~assets/scss/mixins";

    .header {

        &.mine-navbar {

            background-color: transparent;

            transition: background-color .6s;

        }


        .iconfont{

            color: $icon-color-default;

            font-size: $icon-font-size;

        }


        &.header-transition {

            background-color: $header-bgc-translucent;

        }

    }

</style>



base/search-box

<template>

    <div class="mine-search-box-wrapper">

        <i class="iconfont icon-search"></i>

        <div class="mine-search-box" v-if="fake">{{placeholder}}</div>

        <input class="mine-search-box" 

        type="text" 

        :placeholder="placeholder"

        v-model="query"

        v-if="!fake"

        ref="input"

        name="" 

        id="">

        <i class="iconfont icon-close" v-show="query" @click="reset"></i>

    </div>

</template>


<script>

import {debounce} from 'assets/js/util.js'


export default {

    name: 'MeSearchBox',

    props: {

        placeholder: {

            type: String,

            default: '请输入搜索内容'

        },

        fake: {

            type: Boolean,

            default: false

        }

    },

    data() {

        return {

            query: ''

        }

    },

    watch: {

        query: debounce(function(query) {

            console.log(query)

        })

    },

    methods: {

        focus() {

            this.$refs.input && this.$refs.input.focus()

        },

        clear() {

            this.query = ''

        },

        reset() {

            this.clear()

            this.focus()

        }

    }

}

</script>


<style lang="scss">

@import '~assets/scss/mixins';


    $search-box-height: 30px;


    .mine-search-box-wrapper {

        display: flex;

        width: 86%;

        background-color: white;

        height: $search-box-height;

        border-radius: $search-box-height / 2;

        align-items: center;

        padding: 0 7px;


        .mine-search-box {

            flex: 1;

            margin: 0 6px;

            color: #666;

            line-height: 1.5;

        }


        .iconfont {

            font-size: $icon-font-size-sm;

            font-weight: bold;

            color: $icon-color;

        }

    }

    

</style>


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

3回答
好帮手慕星星 2020-03-27 10:08:59

同学你好,自己能够找到问题并解决是很棒的哦!

继续加油~

好帮手慕码 2020-03-26 19:11:58

同学你好,老师测试你的代码。是没有报错的:

http://img1.sycdn.imooc.com//climg/5e7c7f0109434bcd03040131.jpg

查看同学截图的报错,原因是没有在请求接口的方法中添加 catch,同学可以查看下代码。哪里没有添加,可尝试在then()后加上catch()

.catch((e) => {});

祝学习愉快~

  • 提问者 Syrena3447375 #1
    老师,我知道我为啥报错了,我在router/index.js里没写这个 { name: 'search', path: '/search', component: () => import('pages/search') }
    2020-03-26 23:58:36
提问者 Syrena3447375 2020-03-26 17:50:50
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师