当前位置: 首页 > news >正文

幸运快三的网站怎么做西宁网站建设费用

幸运快三的网站怎么做,西宁网站建设费用,制作图官网,经营性质网站文章目录 1.创建Vue项目1.1创建项目1.2 初始项目 2.vue3 语法2.1 复杂写法2.2 简易写法2.3 reactive(对象类型)2.4 ref(简单类型)2.5 computed(计算属性)2.6 watch(监听) 3.vue3 生命周期4.vue3 组件通信4.…

文章目录

        • 1.创建Vue项目
          • 1.1创建项目
          • 1.2 初始项目
        • 2.vue3 语法
          • 2.1 复杂写法
          • 2.2 简易写法
          • 2.3 reactive(对象类型)
          • 2.4 ref(简单类型)
          • 2.5 computed(计算属性)
          • 2.6 watch(监听)
        • 3.vue3 生命周期
        • 4.vue3 组件通信
          • 4.1 父传子(defineProps)
          • 4.1 子传父(defineEmits)
        • 5.vue3 跨组件通信
          • 5.1 跨层传递数据
          • 5.2 跨层传递方法
        • 6.vue3 跨组件通信(pinia)
          • 6.1 下载pinia
          • 6.2 pinia的全局注册
          • 6.3 pinia的使用

1.创建Vue项目

1.1创建项目

项目文件下运行 npm init vue@latest

npm init vue@latest
1.2 初始项目
 npm install

2.vue3 语法

2.1 复杂写法
<script>
export default {setup() {const message = "年后";const messagehandle = () => {console.log(message);};return {message,messagehandle,};},
};
</script>
2.2 简易写法
<script setup>
const message = "你好呀";
const logHandle = () => {console.log(message);
};
</script>

响应式api,完成响应式数据

2.3 reactive(对象类型)
<script setup>
//引入响应式对象
import { reactive } from "vue";
//执行响应式对象
const state = reactive({status: 0,
});
//自定义匿名函数
const addCunt = () => {state.status++;
};
</script>
2.4 ref(简单类型)

ref执行的响应式数据,要用.value接受,


import { ref } from "vue";const state = ref(0);const addCunt = () => {state.value++;
};
2.5 computed(计算属性)

调用computed,返回值用一个常量接受。

<script setup>
import { ref } from "vue";
import { computed } from "vue";
const list = ref([1, 2, 3, 4, 5, 6, 7, 8]);const computedList = computed(() => {return list.value.filter((item) => item > 2);
});
</script>
2.6 watch(监听)

1.监听单个值的变化
2.watch 默认是监听ref浅层监听。

//监听数据的变化
watch(count, (newValue, oldValue) => {console.log(newValue, "+", oldValue);
});

2.监听多个值的变化

//监听数据的变化
watch([count, name], ([newCount, newName], [oldCount, oldName]) => {console.log(newCount, newName, "+", oldCount, oldName);
});
  1. immediate在为触发前执行一次
watch(count,() => {console.log("11");},{immediate: true,}
);

4.深度监听

watch(count,() => {console.log("111");},{deep: true,}
);

3.vue3 生命周期

vue3的生命周期和vue2类似。
在这里插入图片描述

4.vue3 组件通信

4.1 父传子(defineProps)

1.在父组件在vue3中引入子组件,直接使用,不需要注册
2.在子组件通过defineProps接受数据

<script setup>
import { ref } from "vue";
import sonCom from "./components/son.vue";
const number = ref(100);
</script><template><div><sonCom message="小明" :number="number"></sonCom></div>
</template>

<template><div>{{ message }}{{ number }}</div>
</template><script setup>
const count = defineProps({message: String,number: Number,
});
console.log(count.message);
</script><style></style>
4.1 子传父(defineEmits)
<script setup>
import sonCom from "./components/son.vue";
import { ref } from "vue";
const getMessage = (msg) => {console.log(msg);
};
</script><template><div><sonCom @get-message="getMessage"></sonCom></div>
</template>
<template><button @click="sendMsg">按钮</button>
</template><script setup>
const emit = defineEmits(["get-message"]);
const sendMsg = () => {emit("get-message", "5555");
};
</script><style></style>

5.vue3 跨组件通信

provide 发送消息,inject接受消息

5.1 跨层传递数据

发送消息

provide("data-key", count);

接受消息

const message = inject("data-key");
5.2 跨层传递方法
const count = ref(0);
const addcount = () => {count.value++;
};provide("methods", addcount);
const methods = inject("methods");

6.vue3 跨组件通信(pinia)

pinia官网

6.1 下载pinia
npm install pinia
6.2 pinia的全局注册
import './assets/main.css'import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'const pinia=createPinia()createApp(App).use(pinia).mount('#app')
6.3 pinia的使用

在这里插入图片描述

import {defineStore} from 'pinia'
import { ref } from 'vue'
export const useCounterStore=defineStore('counter',()=>{//定义数据const count=ref(0)//定义方法const addCount=()=>{count.value++}//以对象返回数据return{count,addCount}
})

使用pinia

<script setup>
//导入方法
import { useCounterStore } from "./stores/counter";
//执行方法得到实例对象
const useCounter = useCounterStore();
console.log(useCounter);
</script><template><div><button @click="useCounter.addCount">{{ useCounter.count }}</button></div>
</template>
http://www.yayakq.cn/news/95910/

相关文章:

  • 重庆做网站做得好的公司个人简历网页制作教程
  • 传媒公司网站设计私人接单网站开发的能赚多少钱
  • 网站统计热力图手机网站自适应布局怎么做
  • 光谷做网站推广电话wordpress varnish
  • 1688网站怎么样专业做俄语网站建设
  • 学习制作网页的网站查网站的关键词排名吗
  • 企业网站推广的形式有宁波论坛
  • 抚顺清原网站建设招聘衡水的网站建设
  • 家教响应式网站网页此站点不安全
  • 做像58同城样的网站关键词推广优化app
  • 网站建设设计作业如何更快的让百度收录网站
  • h5响应式网站上海上海网页设计是什么
  • 做任务的网站有那些小型网站建设参考文献
  • 网站上的链接怎么做系统首页设计图
  • 个人网站怎么做视频那个软件可以做三个视频网站
  • 电子网站建设公司网站建设和使用现状
  • 关键词优化包年推广搜索引擎排名优化的关键是
  • 南京建设监理协会网站打不开推广项目
  • 网站建设规划书的制作找个做微商授权网站
  • 长沙自助模板建站青白江网站建设
  • 不用js可以做网站吗wordpress插件排行
  • 优秀的网站举例北京网页设计和网页制作
  • 大港油田建设官方网站电商运营培训正规平台
  • 宝华路桥建设集团网站优设网的吉祥物
  • 网页设计与制作题库及答案seo关键词排名优化提升
  • 南通网站推广优化费用赣州火车站找服务
  • 看到网站的第一印象专业网站制作技术
  • 衡阳网站建设价格wordpress打开要10秒
  • 网站建设的售后公司想建一个网站找谁做
  • 行业数据网站怎么在网上做推广