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

沧浪苏州网站建设程序员培训机构

沧浪苏州网站建设,程序员培训机构,新闻源软文推广平台,新泰市建设局网站声明:这只是我个人的学习笔记(黑马),供以后复习用 。一天学一点,随时学随时更新。明天会更好的! 这里只给代码,不给运行结果,看不出来代码的作用我也该进厂了。。。。。 Day1 使用create-vue创建项目。 1.检查版本。 node -v 2.创建项目 npm init vue@latest 可…

声明:这只是我个人的学习笔记(黑马),供以后复习用 。一天学一点,随时学随时更新。明天会更好的!

这里只给代码,不给运行结果,看不出来代码的作用我也该进厂了。。。。。

Day1 使用create-vue创建项目。 

1.检查版本。

node -v

2.创建项目

npm init vue@latest

可以用这个切回国内镜像源

npm config set registry https://registry.npmmirror.com

3. 安装依赖,启动项目

npm install
npm run dev

4.1写法

原始复杂写法setup写法:必须return

<!-- 开关:写组合式组件 -->
<script>
export default {setup() {console.log('setup')const message = 'hello world'const logMessage = () => {console.log(message)}return {//只有return返回一个对象,对象中的属性和方法,都可以在模板中使用message,logMessage,}},beforeCreate() {console.log('beforeCreate')},
}
</script><template><!-- 不再要求唯一的根元素 --><div>{{ message }}<button @click="logMessage">log</button></div>
</template><style scoped></style>

简单的语法糖写法

<script setup>
const message = 'hello world'
const logMessage = () => {console.log(message)
}
</script>
<template><!-- 不再要求唯一的根元素 --><div>{{ message }}<button @click="logMessage">log</button></div>
</template><style scoped></style>

注:1.setup选项在beforeCreate钩子之前自动执行 

        2.setup中的this不指向组件实例了,指向undefined

4.2 函数调用返回响应式数据

reactive()接受对象类型数据的参数传入并返回一个响应式的对象

<script setup>
// 1.导入函数
import { reactive } from 'vue'
//  2.执行函数 传入一个对象类型的函数 变量接受
const state = reactive({count: 0
})
const setCount = () => {state.count++
}
</script>
<template><!-- 不再要求唯一的根元素 --><div><button @click='setCount'>{{ state.count }}</button></div>
</template><style scoped></style>

ref()接受简单类型或对象类型数据的参数传入并返回一个响应式的对象 

脚本区域修改ref的响应式数据 必须通过value属性

<script setup>
// // 1.导入函数
// import { reactive } from 'vue'
// //  2.执行函数 传入一个对象类型的函数 变量接受
// const state = reactive({
//   count: 0
// })
// const setCount = () => {
//   state.count++
// }//1.导入ref 函数
import { ref } from 'vue'
//2.执行函数 传入一个简单类型或者对象类型的参数 变量接受
const count = ref(0)
console.log(count)const setCount = () => {//脚本区域修改ref的响应式数据 必须通过value属性count.value++
}
</script>
<template><!-- 不再要求唯一的根元素 --><div><button @click='setCount'>{{ count }}</button></div>
</template><style scoped></style>

4.3计算属性函数 

computed 返回计算后的数据(不应该有副作用)

<script setup>
// 1.导入computed
import { computed } from 'vue'
import { ref } from 'vue'
const list = ref([1, 2, 3, 4, 5, 6, 7, 8])// 2.使用computed return计算后的值 变量接受
const computedList = computed(() => {return list.value.filter(item => item > 2)
})setTimeout(() => {list.value.push(9, 10)
}, 3000);
</script>
<template><!-- 不再要求唯一的根元素 --><div>原始响应式数据-{{ list }}</div><div>计算后的响应式数据-{{ computedList }}</div>
</template><style scoped></style>

 4.4watch函数 

侦听一个或多个数据的变化,数据变化时执行回调函数(参数:immediate(立即执行),deep(深度侦听))

<script setup>
// import {ref,watch} from 'vue'
// const count = ref(0)
// const setCount = () => {
//   count.value++
// }
// //调用watch方法,监听count的变化
// //watch 里面ref对象不需要加.value属性
// watch(count, (newValue, oldValue) => {
//   console.log(`count发生了变化,老值是${oldValue},新值是${newValue}`);
// })import { ref, watch } from 'vue'
const count = ref(0)
const changeCount = () => {count.value++
}
const name = ref('cp')
const changeName = () => {name.value = 'pc'
}watch([count,name], ([newValue,newName], [oldValue,oldName]) => {console.log(`count或者name发生了变化,老值是${[oldValue,oldName]},新值是${[newValue,newName]}`);
})
</script>
<template><!-- 不再要求唯
http://www.yayakq.cn/news/874709/

相关文章:

  • 随便编一个公司网站怎样给网站找空间做备案
  • iis部署网站 win7广西壮族自治区司法厅官网
  • 网站非法篡改网站图片幻灯片效果
  • 怎么实现网站建设报价方案网站注册查询官网
  • 抖音网站建设的基本情况wordpress 论坛app
  • 济南app网站建设百度新闻头条新闻
  • 网站开发与设计结课论文网站的目标客户是
  • 珠海制作公司网站用dw制作网站模板下载地址
  • dede 购物网站做网页设计师需要学什么
  • 微信 公司网站 怎么做不良网站正能量免费下载
  • 大名网站建设费用雄安免费网站建设电话
  • 关于大棚建设的网站商品网站建设实验报告
  • 比较好的网页模板网站wordpress 数据库 改ip
  • 中国网站空间wordpress 公网贷款
  • 3000ok新开传奇网站石家庄网站快速优化排名
  • 地方文明网站建设措施流量打不开网站怎么办
  • 刘金鹏做网站wordpress 豆瓣主题
  • 女人与狗做网站办公家具
  • 做酸菜视频网站岳阳公司网站开发
  • 网站动态页面怎么做wordpress打赏key插件
  • 购物网站建设 优帮云公司注册域名怎么申请
  • 学生自做网站优秀作品新手学做网站电子版
  • 网站开发小组沈阳蓝德网站建设
  • 网站内链怎么删除种子资源地址
  • o2o网站建设策划新闻热点事件2021(最新)
  • 东莞百度代做网站联系方式企业官方网站怎么写
  • 代理怎么引流推广seo网络推广经理招聘
  • 服务好的网站开发郑州微信网站制作
  • 昆明专业做网站网站备案个人信息
  • 做网站要用到哪些架包鄂州网站建设设计