2021-07-29

自己封装组件

1.建一个test.Vue文件内容如下

<template>
  <div>
    <el-button v-for="(btn,index) in this.buttons" :key="btn.id" :type="btn.type ? btn.type:'primary'"
               :icon="btn.icon" :size="btn.size?btn.size:'mini'">{{btn.label}}
    </el-button>
  </div>
</template>
<script>
export default {
  name: "buttonTemplate",
  props: {
    buttons: {
      type: Array,     //type是类型的意思;类型有String Number Boolean Function Object Array Symbol
      required: true   //可以使用required选项来声明这个参数是否必须传入。
    }
  }
}

谁用谁引入
父组件

import myButton from "../components/btn/btn.vue"

<div class="home">
  <my-button :buttons = "buttons"></my-button>
</div>
data(){
  return {
    buttons:[
      {
        label:"创建",
        icon:"el-icon-circle-plus",
        size:"mini",
        type:"primary"
      },
      {
        label:"修改",
        icon:"el-icon-remove",
        id:1,
        size:"medium",
        type: "success"
      },
      {
        label:"导入",
        icon:"el-icon-success",
        id:2,
        size:"small",
        type:"warning",
      }
    ]
  }
},
components:{
  myButton
}

Vue X

只能在mutaions里修改state,actions不能直接修改state
Commit方法执行mutation ; dispatch方法来执行actions

Eg:
在Vuex中写的内容


```javascript

```javascript

```javascript

```javascript

```javascript

```javascript

```javascript

```javascript

```javascript

```javascript
state: {
    val:{
      name:"郑",
      age:18,
      sex:"男"
    },
    count:0,
    goods:[]
},
getters:{
  totalNum:function (state) {
    let a = 0;
    state.goods.forEach(item=>{
      a = a + item.num
    })
    return a
  }
},
mutations: {
  increment (state){
    state.count++
  },
  newName(state,msg){
    state.val.sex = msg
  },
  init(state,goods){
      state.goods = goods
  }
},
actions: {
  getCart(plyload){
    request.get('/mi/cart.php')
        .then(res=>{
//init是执行的mutations里面的方法所以yongcommit
Res.data是传入到init中的值
          plyload.commit("init",res.data)
        })
        .catch(err=>{
          console.log(err)
        })
  }
},

在需要用到数据的.vue文件中写

sum(){
  console.log(this.$store.state.val.sex)
//newName是mutations里面的方法需要用commit去执行后面的是向newName里面传入的参数
  this.$store.commit('newName',this.price.zz)
//dispatch是操作的异步数据的方法
  this.$store.dispatch("getCart")
  console.log(this.$store.state.val.sex)

},
sums(){
  console.log(this.$store.state.goods)
}

VueX中的modules

第一步先建立一个.js结尾的文件
内容是export default{
Namespaced:true(这样就能在全局访问到这个模块中的各个状态方法)

state:{
name:”证书彬”
}
mutations:{getUser(context){
    console.log("我是模块中的方法")
    console.log(context,"我是模块中同步的context")
}
actions:{
    getData(context){
        console.log("我是模块中的方法")
        console.log(context,"我是模块中异步的context")
    }
},

modules:{}
}

第二步在store中的.js中导入刚建的那个.js文件

第三步在store中的.js中的modules中写上刚才导入的.js的文件名
想要在用Vuex的.vue文件中取到模块中的state中的数据方法 this.$store.$state.user.name
取出模块中的方法 this.$store.commit(“user/getuser”)
第一个user是这个模块的名称(也就是在index.js中module中填写的名称) getuser是方法名
同步中的context只携带了此模块的state中的数据 //操作根vuex的
异步中的context携带了commit dispatch getters rootGetters rootState 此模块的state中的数据

父向子传值

子组件com.vue
以下内容在父组件中写的
第一步导入子组件

import son from '../components/com.vue'

注册组件

components:{son}

在template中使用组件

//第一个fontSize是子组件需要在props里面写的名字
//第二个fonSize是父组件里面需要传递给子组件的值
<son@childByValue="getChildValue" :fontSize="fontSize"></son>

以下内容在子组件中写的
这里的fontSize名称必须和父组件中v-bind后绑定的名字一致
//type是类型的意思;类型有String Number Boolean Function Object Array Symbol
//可以使用required选项来声明这个参数是否必须传入。
props:{fontSize:{type:String,required: true
}}
子向父传值
下面内容在子组件中写
设置一个点击事件用来出发KaTeX parse error: Expected '}', got 'EOF' at end of input: …传递过去的数据 this.emit(‘childByValue’, this.names)
}

下面内容在父组件中写

<son@childByValue="getChildValue" :fontSize="fontSize"></son>
getChildValue(childValue) {
// childValue就是子组件传过来的值
      this.childName = childValue
    }

组件与组件之间的传值-事件总线
先建立一个bus.js文件
a组件把内容发送到b组件
在两个组件都需要导入bus.js文件
a组件内容

handleClick () {
  bus.$emit('pao', this.elValue)
  this.$router.push("/bro2")
}

B组件内容

created(){
  console.log("____________________--")
  bus.$on('pao', (val) => {
    console.log(val)
    this.text = val
  })
},

element中面包屑的使用
进行判断目前的路径(path)是否在首页,在首页不显示面包屑

<el-breadcrumb v-if="this.$router.currentRoute.path!=='/admin/shop'">

设置首页的路径

  <el-breadcrumb-item :to="{ path: '/admin/shop' }">首页</el-breadcrumb-item>

获取当前所在所在页面中路由中的name的值

<el-breadcrumb-item>{{this.$router.currentRoute.name}}</el-breadcrumb-item>
</el-breadcrumb>

给elementui添加回车事件

需要在输入框中添加回车事件@keyup.enter.native="触发的函数"
//路由守卫
//写在main.js中
router.beforeEach((to,from,next) => {
    if(localStorage.getItem("userid")){
      next(true);
    }
  else{
    console.log("我是否则")
    if (to.path === '/'){
      next();
      console.log("我是首页")
    }else {
      next('/?redirect='+to.path)
      console.log("我是redirect")
    }
  }
})
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我! 毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip
以下是一个可能的Java实现: ```java import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; public class RentPlanGenerator { private static final double RENT_INCREASE_RATE = 0.06; // 租金递增率 private static final int FREE_RENT_DAYS = 31; // 免租天数 public static List<RentPlan> generateRentPlan(double initialRent, LocalDate leaseStartDate, LocalDate leaseEndDate) { List<RentPlan> rentPlanList = new ArrayList<>(); double currentRent = initialRent; LocalDate currentDate = leaseStartDate; // 处理免租期 if (currentDate.isBefore(leaseStartDate.plusDays(FREE_RENT_DAYS))) { currentDate = leaseStartDate.plusDays(FREE_RENT_DAYS); } while (currentDate.isBefore(leaseEndDate)) { LocalDate nextIncreaseDate = currentDate.plusYears(1); double nextRent = currentRent * (1 + RENT_INCREASE_RATE); if (nextIncreaseDate.isBefore(leaseStartDate.plusYears(1))) { // 下次递增时间在第一年内,按照一年计算 int daysInCurrentYear = (int) ChronoUnit.DAYS.between(currentDate, nextIncreaseDate); rentPlanList.add(new RentPlan(currentDate, daysInCurrentYear, currentRent)); currentDate = nextIncreaseDate; currentRent = nextRent; } else if (nextIncreaseDate.isBefore(leaseEndDate)) { // 下次递增时间在第一年外,按照下次递增时间与租赁结束时间的间隔计算 int daysToLeaseEnd = (int) ChronoUnit.DAYS.between(currentDate, leaseEndDate); rentPlanList.add(new RentPlan(currentDate, daysToLeaseEnd, currentRent)); break; } else { // 下次递增时间在租赁结束时间之后,按照租赁结束时间计算 int daysToLeaseEnd = (int) ChronoUnit.DAYS.between(currentDate, leaseEndDate); rentPlanList.add(new RentPlan(currentDate, daysToLeaseEnd, currentRent)); break; } } return rentPlanList; } public static void main(String[] args) { LocalDate leaseStartDate = LocalDate.of(2021, 3, 1); LocalDate leaseEndDate = LocalDate.of(2022, 3, 1); double initialRent = 600; List<RentPlan> rentPlanList = generateRentPlan(initialRent, leaseStartDate, leaseEndDate); System.out.printf("%-12s%-12s%-12s%n", "时间", "天数", "租金"); for (RentPlan rentPlan : rentPlanList) { System.out.printf("%-12s%-12d%-12.2f%n", rentPlan.getStartDate(), rentPlan.getDays(), rentPlan.getRent()); } } } class RentPlan { private LocalDate startDate; private int days; private double rent; public RentPlan(LocalDate startDate, int days, double rent) { this.startDate = startDate; this.days = days; this.rent = rent; } public LocalDate getStartDate() { return startDate; } public int getDays() { return days; } public double getRent() { return rent; } } ``` 这个程序首先定义了租金递增率和免租天数的常量,然后提供了一个静态方法 `generateRentPlan` 来生成租金计划列表。该方法接受三个参数:初始月租金、租赁开始时间和租赁结束时间。 具体实现时,我们使用循环来逐月生成租金计划。在每次循环中,我们首先计算下次递增租金的时间和金额。然后根据下次递增时间与租赁开始时间的间隔,决定本次循环处理的天数和租金金额。最后将这些信息保存到一个 `RentPlan` 对象中,并添加到租金计划列表中。 在主函数中,我们使用 `generateRentPlan` 方法生成租金计划列表,并以表格形式输出。输出结果如下: ``` 时间 天数 租金 2021-04-01 30 600.00 2021-05-01 31 636.00 2021-06-01 30 674.16 2021-07-01 31 713.57 2021-08-01 31 754.29 2021-09-01 30 796.39 2021-10-01 31 840.94 2021-11-01 30 887.02 2021-12-01 31 934.72 2022-01-01 31 984.12 2022-02-01 28 1035.30 ``` 可以看到,程序正确地根据递增周期和递增率生成了每个月的租金计划,并且考虑了免租期的影响。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值