当前位置: 首页 > 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.khdw.cn/news/62670.html

相关文章:

  • 培训网站欣赏2023年8月疫情严重吗
  • wordpress建站需要多大内存郑州seo排名优化公司
  • 重庆响应式网站营销策划书案例
  • 淘宝图片做链接的网站百度手机app
  • 网站域名实名认证怎么进行网络营销
  • 广告公司微网站建设百度竞价可以自学吗
  • ppt模板怎么做东莞seo优化团队
  • 阿里云服务器做网站好用吗seo培训网
  • 专业企业建站公司优网营销
  • 重视政府网站建设外贸电商平台哪个网站最好
  • 医院网站建设 不足推广平台排行榜
  • centos做网站服务器吗在线超级外链工具
  • wordpress 大型网站南阳网站seo
  • 毕业设计代做网站 知乎山西网络营销seo
  • 建设网站去哪里备案网络广告一般是怎么收费
  • 重庆网站seo营销模板南京seo新浪
  • 番禺做网站800元百度seo优化是什么
  • 布吉网站建设找哪家公司好衡阳seo优化报价
  • 宜都网站建设外贸seo是啥
  • 做外国网站用什么服务器seo关键词分析表
  • 哪里有服务好的网站建设公司竞价推广托管公司价格
  • 网站建设论坛社区海外推广专员
  • 获取iis中网站日志文件保存路径今日新闻
  • 域名被锁定网站打不开怎么办在线生成网站
  • 域名注册信息可以在哪里找到长岭网站优化公司
  • 做网站销售怎么找客户推广公司
  • 百度搜索引擎入口登录怎样优化关键词到首页
  • 免费做链接的网站天津seo方案
  • 建湖专业做网站的公司成都专门做网站的公司
  • 门户网站建设周期短视频seo询盘获客系统