word和use的bug,估计是vue-cli版本带来的问题,不知道怎么解决

news/2024/7/9 23:41:02 标签: vue

hami072里的,无法解决了,应该是。

采用的什么办法呢,倒推的。应该是之前的版本,可以。倒推的文件夹是bookstore3.0

router/index.js

import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/Home'
import store from '@/store'

const routes = [
  {
    path: '/',
    redirect: {
      name: 'home'
    }
  },
  {
    path: '/home',
    name: 'home',
    meta: {
      title: '首页'
    },
    component: Home
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

//设置页面的标题
router.afterEach((to) => {
  document.title = to.meta.title;
})

router.beforeEach(to => {
  // 判断该路由是否需要登录权限
  if (to.matched.some(record => record.meta.requiresAuth))
  {
    // 路由需要验证,判断用户是否已经登录
    if(store.state.user.user){
      return true;
    }
    else{
      return {
        path: '/login',
        query: {redirect: to.fullPath}
      };
    }
  }
  else
    return true;
})

export default router

App.vue

<template>
  <div id="app">
    <Header/>
    
    <router-view/>
  </div>
</template>

<script>
import Header from '@/components/Header.vue'


export default {
  components: {
    Header,
    
  },

  
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  width: 1200px;
}


</style>

为什么里头是header而不是home呢?app.vue里,为什么?

views/Home.vue

<template>
  <div class="home" v-cloak>

  </div>
</template>

<script>

export default {
  name: 'home',
  components: {
  
  }
}
</script>
<style scoped>
.home {
  float: left;
  text-align: center;
  width: 100%;
}
[v-cloak]{
  display: none;
}
</style>

Header.vue

<template>
  <div class="header">
    <img src="@/assets/images/logo.png">
    <HeaderSearch />
    <HeaderCart/>
    <span v-if="!user">你好,请<router-link to="/login">登录</router-link>  免费<router-link to="/register">注册</router-link></span>
    <span v-else>欢迎您,{{ user.username }}<a href="javascript:;" @click="logout">退出登录</a></span>
  </div>
</template>

<script>
import HeaderSearch from "./HeaderSearch";
import HeaderCart from "./HeaderCart";
import { mapState, mapMutations } from 'vuex'

export default {
  name: "Header",

  components: {
    HeaderSearch,
    HeaderCart
  },

  computed: {
    // user模块带有命名空间
    ...mapState('user', [
      // 将this.user 映射为 this.$store.state.user.user
      'user'
    ])
  },

  methods: {
    logout(){
      this.deleteUser();
    },
    // user模块带有命名空间
    ...mapMutations('user', [
      // 将this.deleteUser 映射为 this.$store.commit('user/deleteUser')
      'deleteUser'
    ])
  },
};
</script>
<style scoped>
.header {
    width: 100%;
    /*position: relative;*/
}
.header img{
    width: 200px;
    height: 60px;
    margin: auto;  
}
.header span{
  margin-left: 20px;
}
.header a{
  text-decoration: none;
  color: red;

}
</style>

HeaderCart.vue

<template>
  <div class="headerCart">
      <a href="javascript:;" @click.prevent="handleCart">
          <span>购物车{{ cartItemsCount }}</span>
      </a>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  export default {
    name:'HeaderCart',
    components: {},
    computed: {
      //cart模块带有命名空间
      ...mapGetters('cart', {
        //Vuex的store中定义的一个getter,得到购物车中商品的数量
        // 将this.cartItemsCount 映射为 this.$store.getters['cart/itemsCount']
        cartItemsCount: 'itemsCount'
      })
    },

    methods: {
      handleCart(){
        this.$router.push("/cart");
      }
    },
  }
</script>
<style scoped>
.headerCart {
    display: inline-block; 
    position: relative;
    text-align: center;
    width: 100px;
    height: 30px;
    margin-top: 20px;
    margin-bottom: 20px;
    cursor: pointer;
    margin-left: 20px;
    background-color:red;
    vertical-align: middle;
}

.headerCart a {
    text-decoration: none;
    color: white;
    
}
.headerCart a > span{
  position: absolute;
  left: 2px;
  right: 2px;
  bottom: 5px;
}
</style>

HeaderSearch.vue

<template>
  <div class="headerSearch">
      <input type="search" v-model.trim="keyword">
      <button @click="search">搜索</button>
  </div>
</template>

<script>

  export default {
    name:'HeaderSearch',
    data () {
      return {
        keyword: ''
      };
    },
    methods: {
      search(){
        // 当查询关键字与当前路由对象中的查询参数wd值不同时,才调用$router.push方法
        if(this.keyword != this.$route.query.wd)
            this.$router.push({path: '/search', query: {wd: this.keyword}})
      }
    },
  }
</script>
<style scoped>
.headerSearch {
    display: inline-block; 
    position: relative;
}
.headerSearch input {
    width: 400px;
    height: 30px;
}

.headerSearch button{
    position: absolute;
    right: 0px;
    top: 0;
    width: 60px;
    height: 30px;
    margin: 0;
    border: none;
    color: white;
    background-color: red;
    cursor: pointer;
}
</style>

main.js

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import VueAxios from 'vue-axios'
//import ElementPlus from 'element-plus';
import { ElPagination } from 'element-plus'
import 'element-plus/lib/theme-chalk/index.css'
//import locale from 'element-plus/lib/locale/lang/zh-cn'
import lang from 'element-plus/lib/locale/lang/zh-cn'
import locale from 'element-plus/lib/locale'

axios.defaults.baseURL = "/api"

// 使用中文语言
locale.use(lang)

//createApp(App).use(store).use(router).use(VueAxios, axios).use(ElementPlus,{ locale }).mount('#app')
createApp(App).use(store).use(router).use(VueAxios, axios).use(ElPagination, { locale }).mount('#app')



http://www.niftyadmin.cn/n/957166.html

相关文章

matlab v4l2,基于Linux的v4l2视频架构驱动编写

3&#xff0e; 控制命令VIDIOC_S_FMT //直接告诉你&#xff0c;s是set的意思功能&#xff1a; 设置视频设备的视频数据格式&#xff0c;例如设置视频图像数据的长、宽&#xff0c;图像格式(JPEG、YUYV格式)&#xff1b;参数说明&#xff1a;参数类型为V4L2的视频数据…

python set 嵌套,如何在Python中设置嵌套对象的属性?

我第一次尝试Python。在我需要遍历一个日志&#xff0c;解析日志条目&#xff0c;然后更新一个对象&#xff0c;其中包括日志中列出的机器的嵌套对象。在这就是我所拥有的&#xff1a;import reformat_pat re.compile(r"(?P(?:[\d\.]|[\da-fA-F:]))\s"r"(?P\…

HeaderSearch.vue的写法

自己写的错误的 <template><div class"headercart"><input type"text"></input><button click"search">搜索</button></div> </template><script> export default {name: "HeaderS…

php 栈加密,PHP 数据结构与算法之《栈》_php

介绍“要成高手&#xff0c;必练此功”。要成为优秀的程序员&#xff0c;数据结构和算法是必修的内容。而现在的web程序员使用传统算法和数据结构都比较少&#xff0c;因为很多算法都是包装好的&#xff0c;不用我们去操心具体的实现细节&#xff0c;如php的取栈操作array_pop,…

正确的HeaderSearch.vue,两相比较一下

<template><div class"headerSearch"><input type"search" v-model.trim"key.word"><button click"search">搜索</button></div> </template><script> export default {name: Header…

php取客端口ip,PHP取客户IP以及所属地

PHP对客户IP的操作有很多学PHP的小伙伴取客户IP的时候不够精确&#xff0c;下面是比较精确的方法&#xff0c;拿小本本记一下&#xff01;获取客户端IP地址function get_client_ip($type 0,$advtrue) {$type $type ? 1 : 0;static $ip NULL;if ($ip ! NULL) return $ip[$ty…

终于好了,报word bug(Cannot read properties of undefined (reading ‘word‘) )的原因,就是自己把vue文件中的单词写错了

HeaderSearch.vue这个文件夹中 再看看自己之前的&#xff0c;应该&#xff0c;可能&#xff0c;肯定&#xff0c;也是单词写错了。 改完了以后&#xff0c;对比一下试试。 Cannot read properties of undefined (reading ‘word‘) bug keyword写成了key.word和query写成了q…

oracle+修改表空间状态,oracle查看表空间的属性 ,修改表空间的状态

表空间的状态属性主要有在线(online)&#xff0c;离线(offline)&#xff0c;只读(read only)和读写(read write)这四种&#xff0c;其中只读与读写状态属于在线状态的特殊情况&#xff0c;通过设置表空间的状态属性&#xff0c;我们可以对表空间的使用进行管理。在线当表空间的…