• boomYouth


    上一周实在是过得太颓废了,我感觉还是要把自己的规划做好一下:

    周计划

    这周截至周四,我可以用vue简单的画完登陆注册的界面并且弄一点预处理:

    周一

    的话可以把这些都学一下:

    父传子,子传父:
    1. <script setup>
    2. // 1.给子组件以添加属性的方式传值
    3. // 2.在子组件通过props的方式接受
    4. // 对于局部组件,导入进来就能用
    5. import testDemo1 from './components/test-demo1.vue';
    6. import{ref} from 'vue';
    7. const money=ref(100);
    8. const getMoney=()=>
    9. {
    10. money.value+=10;
    11. }
    12. const changeFf=(newMoney)=>{
    13. money.value=newMoney;
    14. }
    15. </script>
    16. <template>
    17. <h3>我是父组件---{{ money }}</h3>
    18. <!-- 给子组件添加属性的方式传值 -->
    19. <testDemo1 car="宝马"
    20. :money="money"
    21. @changeMoney="changeFf"
    22. ></testDemo1>
    23. <button @click="getMoney"></button>
    24. <!-- 也可以动态传递子属性数据 -->
    25. money
    26. </template>
    1. <script setup>
    2. // 注意:由于写了setup,所以无法配置props选项
    3. // 借助编译器宏函数接受子组件传递的数据,是编译阶段的一个标识,实际编译器解析后遇到后会进行编译转换
    4. const emit=defineEmits(['changeMoney']);
    5. const props=defineProps({
    6. car:String,
    7. money:Number
    8. })
    9. const buy=()=>
    10. {
    11. //单向流需要emit去触发事件
    12. emit('changeMoney',5);
    13. }
    14. console.log(props.car)
    15. </script>
    16. <template>
    17. <div class="son">
    18. 我是子组件---{{ car }}-----{{ money }}
    19. <button @click="buy">花钱</button>
    20. </div>
    21. </template>
    22. <style scoped>
    23. .son{
    24. padding: 30px;
    25. border: red solid 1px;
    26. }
    27. </style>
    defineExpose和模板引用 :

    默认在setup语法糖下是不开放组件内部的方法和属性的,可以通过defineExpose向外暴露;

    1. <script setup>
    2. import { onMounted, ref } from 'vue';
    3. import testDemo2 from './components/test-demo2-copy.vue';
    4. // 模板引用(可以获取dom,也可以获取组件)
    5. /* 1.调用ref函数,创建ref对象
    6. 2。通过ref标识,进行绑定
    7. 通过ref对象,.value即可访问绑定的元素(必须渲染完成后才能拿到) */
    8. const inp=ref(null);
    9. //-------------------------------------
    10. const testRef=ref(null);
    11. const getCom=()=>
    12. {
    13. console.log(testRef.value.count);
    14. }
    15. //生命周期钩子
    16. onMounted(()=>{
    17. console.log(inp.value)
    18. inp.value.focus();
    19. });
    20. </script>
    21. <template>
    22. <input ref="inp" type="text">
    23. <button>点击让输入框聚焦</button>
    24. <testDemo2 ref="testRef"></testDemo2>
    25. <button @click="getCom">获取组件</button>
    26. </template>
    1. <script setup>
    2. import { ref } from 'vue';
    3. const count=ref(999);
    4. const sayHi=()=>
    5. {
    6. console.log("你好呀");
    7. }
    8. defineExpose({
    9. // 使用宏向外暴露
    10. sayHi,
    11. count
    12. });
    13. </script>
    14. <template>
    15. <div>我是用于测试的组件--{{ count }}</div>
    16. </template>

    同时去搜索了一下vue里面响应式和非响应式的数据有什么区别:

    provide和inject:

    从顶层组件向任意底层组件传递数据和方法:

    1. <script setup>
    2. import centerCom from '@/components/center-com.vue'
    3. import {ref,provide} from 'vue'
    4. //跨层级传递普通数据
    5. provide('theme-color','小冏');
    6. //跨层级传递响应式数据
    7. const count=ref(100);
    8. provide('count',count);
    9. //跨层级传递函数
    10. provide('changeCount',(newValue)=>
    11. {
    12. count.value=newValue;
    13. })
    14. </script>
    15. <template>
    16. <div><h1>我是顶层组件</h1></div>
    17. <centerCom></centerCom>
    18. </template>
    1. <script setup>
    2. import bottomCom from '@/components/bottom-com.vue'
    3. </script>
    4. <template>
    5. <div><h2>我是中间组件</h2></div>
    6. <bottomCom></bottomCom>
    7. </template>
    1. <script setup>
    2. import { inject } from 'vue';
    3. const themeColor=inject('theme-color');
    4. const count=inject('count');
    5. const changeCount=inject('changeCount');
    6. const clickFn=()=>
    7. {
    8. changeCount(500);
    9. }
    10. </script>
    11. <template>
    12. <div><h3>我是底层组件--{{ themeColor }}---{{ count }}</h3></div>
    13. <button @click="clickFn">修改count</button>
    14. </template>
     defineOptions:

    1. <script setup>
    2. defineOptions({
    3. name:'loginIndex'
    4. })
    5. </script>
    6. <template>
    7. <div>
    8. 哈哈哈哈
    9. </div>
    10. </template>

    然后好奇的又搜了一下有关setup语法糖的作用:

    Vue3.0的新语法糖-script setup - 知乎 (zhihu.com)

    defineModel:
    1. <script setup>
    2. import myInput from './components/my-input.vue';
    3. import { ref } from 'vue';
    4. const counts=ref('123456');
    5. </script>
    6. <template>
    7. <div><div>
    8. <myInput type="text"
    9. v-model="counts"
    10. ></myInput>
    11. {{ counts }}
    12. </div></div>
    13. </template>
    1. <script setup>
    2. import { defineModel } from 'vue';
    3. const modelValue=defineModel();
    4. </script>
    5. <template>
    6. <div>
    7. <input
    8. type="text"
    9. :value="modelValue"
    10. @input="e=>modelValue=e.target.value"
    11. >
    12. </div>
    13. </template>
    Pinia:

    Pinia基本语法 :
    1. <script setup>
    2. import { useCountStore } from '../store/counter';
    3. const counterStore=useCountStore();
    4. </script>
    5. <template>
    6. <div>
    7. 我是son1
    8. {{ counterStore.count }}
    9. --<button @click="counterStore.addCount">+</button>
    10. </div>
    11. </template>
    12. <style scoped>
    13. </style>
    1. <script setup>
    2. import { useCountStore } from '../store/counter';
    3. const counterStore=useCountStore();
    4. </script>
    5. <template>
    6. <div>
    7. 我是son2
    8. {{ counterStore.count }}
    9. --<button @click="counterStore.subCount">-</button>
    10. </div>
    11. </template>
    12. <style scoped>
    13. </style>
    1. <script setup>
    2. import sonCom1 from '@/components/sonCom1.vue'
    3. import sonCom2 from '@/components/sonCom2.vue'
    4. import {useCountStore} from '@/store/counter'
    5. const counterStore=useCountStore();
    6. console.log(counterStore);
    7. </script>
    8. <template>
    9. <div>
    10. <h3>根组件-{{counterStore.count}}</h3>
    11. <sonCom1></sonCom1>
    12. <sonCom2></sonCom2>
    13. </div>
    14. </template>
    15. <style scoped>
    16. </style>
    1. import { defineStore } from "pinia";
    2. import { ref } from "vue";
    3. //定义store
    4. //仓库里面修改数据都是靠导出来修改的
    5. export const useCountStore=defineStore('counter',()=>
    6. {
    7. //声明数据 state-count
    8. const count=ref(0);
    9. //声明操作数据的方法-actions
    10. const addCount=()=>{
    11. count.value++
    12. }
    13. const subCount=()=>{
    14. count.value--;
    15. }
    16. //声明基于数据派生的计算属性getters
    17. return {
    18. count,
    19. addCount,
    20. subCount
    21. }
    22. });
     pinia-action异步写法:

    数据库的作业:

    周二:

    上午词汇,下午翻译训练; 

    周三

    写一下java作业以及上午词汇训练

    周四:

    上午词汇训练,下午范文复习

    明天和意外,我永远不知道哪个先发生。。。 

    其实这几天多了很多其它的事情,所以进度直接跳到周天:

    周日:

    录题,数据库作业,各种作业

    保证书:

    对于时长除了每天3.5小时*6=21小时

    大概每天可以拿出一个半小时多余时间出来自习:1.5*6=9小时

    然后周六2+3=5小时可以用来自习,还有周二没什么课几乎1小时

    21+9+5+1=36小时一周;

    刷题的话我打算用c++,但是还不会,力扣也没怎么刷过,所以先试试一周写五道题;

    功能点:

    第三周的时候开始写项目,在此之前会先用vue先画一下登陆注册的界面和前端;

  • 相关阅读:
    vue基于vant实现图片上传
    el-select多选文字过长导致溢出
    vue本地开发设置代理连接本地后台服务
    致敬最美抗击疫情的逆行者 DIV布局大学生抗疫感动专题网页设计作业模板 疫情感动人物静态HTML网页模板下载
    【Python】正则re的使用
    【工具使用】代码行数统计的方法汇总
    Windows系统配置CUDA编程环境
    vscode Coder Runner 运行C++
    【Java面试】@Resource 和 @Autowired 的区别
    [machine learning]误差分析,模型分析
  • 原文地址:https://blog.csdn.net/weixin_74789176/article/details/134384334