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

网站关键词如何设置西安seo排名

网站关键词如何设置,西安seo排名,昆明网站建设优化,莱芜都市网征婚交友目录 template 属性 data 属性 methods 属性 疑问 function 函数的两种写法 methods 属性中 this 的指向 总结 Vue 实例是通过 Vue.createApp() 创建的,该函数需要接收一个对象作为参数,该对象可添加 template、data、methods 等属性。 template …

目录

template 属性

data 属性

methods 属性

疑问

function 函数的两种写法

methods 属性中 this 的指向

总结


Vue 实例是通过 Vue.createApp() 创建的,该函数需要接收一个对象作为参数,该对象可添加 template、data、methods 等属性。

template 属性

vue.js 3 中的 template 属性用于定义需要渲染的模板内容,其中包括 html 标签或组件,最终将其挂载到 元素上,相当于为 innerHTML 赋值。

在模板中,会使用一些语法,例如 {{}} 和 @click 等。

data 属性

data 属性用于为 vue.js 组件定义响应式数据,该属性需要传入一个函数,该函数返回一个对象。

该对象会被 vue.js 劫持,之后对该对象的修改或访问都会在劫持中被处理,所以该对象中定义的数据都是响应式的。

例如,在 template 中通过使用 {{counter}},可访问到该对象定义的 counter;当修改 counter 时,template 中的 {{counter}} 也会发生改变。

在浏览器中运行代码时,需要注意。

在 vue.js 2 中,data 属性可传入一个对象。

在 vue.js 3 中,data 属性必须传入一个函数,否则会在浏览器中报错。

methods 属性

methods 属性需要传入一个对象,通常会在这个对象中定义很多方法,可以被绑定到模板中,在该方法中,可以使用 this 直接访问 data 返回对象的属性。

methods 中定义的方法不能使用箭头函数。

疑问

为什么 methods 属性中定义的方法不能使用箭头函数?

https://v2.cn.vuejs.org/v2/api/#methods

https://cn.vuejs.org/api/options-state.html#methods

function 函数的两种写法

// function 函数的简写语法
decrement() {this.counter--;console.log('decrement=>', this)
},
// function 函数的完整语法
decrement:function() {this.counter--;
}

可知,简写是在完整的基础上少了 :function

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body><div id="app"></div><!-- 用 <template> 标签编写模板内容,需要添加 id 属性 --><template id="why"><div><h2>{{message}}</h2><h2>{{counter}}</h2><button @click="increment">+1</button><button @click="decrement">-1</button></div></template><script src="./js/vue.js"></script><script>Vue.createApp({template: '#why', // 通过id选择器选中 <template id="why"></template> 模板data: function() {return {message: "methods中的this",counter: 100}},methods: {// 1.箭头函数increment:() => {this.counter++;console.log('increment=>', this)},// 2.function 函数的简写语法decrement() {this.counter--;console.log('decrement=>', this)},// 3.function 函数的完整语法// decrement:function() {//     this.counter--;// }}}).mount('#app');</script>
</body>
</html>

在浏览器中运行代码,f12 打开控制台,先点击 -1 按钮,再点击 +1 按钮,控制台输出如下

箭头函数中的 this 会指向 Window,这里涉及箭头函数使用 this 的查找规则,它会在自己上层作用域中查找 this。这里找到的刚好是 script 作用域中的 this,所以就是 Window。

就是 vue.js 在执行过程中创建了一个 Proxy 对象,通过代理对象来处理数据,不是js原生的 Window 对象。

methods 属性中 this 的指向

在 vue.js 3源码中,所在在 methods 中定义的方法都会被遍历,通过 bind 函数绑定 this,确保方法中的 this 指向 vue 实例的代理对象。

​​​​​​https://github.com/vuejs/core/blob/v3.2.23/packages/runtime-core/src/componentOptions.ts#L633

通过 bind() 为每个函数绑定了 publicThis,即 vue 实例的代理对象。

https://github.com/vuejs/core/blob/v3.2.23/packages/runtime-core/src/componentOptions.ts#L544

除了 methods 中的 this 指向 vue 实例的代理对象,data、computed、watch 等也都绑定了同一个 this。

Vue.createApp() 的对象除了可以编写 template、data、methods 属性,还可以定义其他属性,比如 props、computed、watch、emits、setup 和生命周期函数等。

总结

Vue.createApp的对象参数

属性名作用注意事项
template定义需要渲染的模板内容
data为 vue.js 组件定义响应式数据该属性需要传入一个函数,该函数返回一个对象
methods需要传入一个对象,通常会在这个对象中定义很多方法,可以被绑定到模板中,在该方法中,可以使用 this 直接访问 data 返回对象的属性。methods 中定义的方法不能使用箭头函数。


文章转载自:
http://dinncopivot.tqpr.cn
http://dinncoskat.tqpr.cn
http://dinncoholdfast.tqpr.cn
http://dinncohephaestus.tqpr.cn
http://dinncofought.tqpr.cn
http://dinncothwartwise.tqpr.cn
http://dinncoeyespot.tqpr.cn
http://dinncosupplicatingly.tqpr.cn
http://dinncofloating.tqpr.cn
http://dinncotuft.tqpr.cn
http://dinncoindirect.tqpr.cn
http://dinncopiagetian.tqpr.cn
http://dinncoinaugurator.tqpr.cn
http://dinncorhapsodist.tqpr.cn
http://dinncoindignant.tqpr.cn
http://dinncolovely.tqpr.cn
http://dinncopelecaniform.tqpr.cn
http://dinncohydrosome.tqpr.cn
http://dinncolymphoma.tqpr.cn
http://dinncocrick.tqpr.cn
http://dinncotantalite.tqpr.cn
http://dinncoseamless.tqpr.cn
http://dinncocrisper.tqpr.cn
http://dinncoamerasian.tqpr.cn
http://dinncohowl.tqpr.cn
http://dinncomatinee.tqpr.cn
http://dinncosubjunction.tqpr.cn
http://dinncounroof.tqpr.cn
http://dinncoremain.tqpr.cn
http://dinncohistoricize.tqpr.cn
http://dinncobilliardist.tqpr.cn
http://dinncopyrite.tqpr.cn
http://dinncomuggur.tqpr.cn
http://dinncopeacockish.tqpr.cn
http://dinncocinephile.tqpr.cn
http://dinncopetty.tqpr.cn
http://dinncomacromere.tqpr.cn
http://dinncoaerobium.tqpr.cn
http://dinncotestudo.tqpr.cn
http://dinncologged.tqpr.cn
http://dinncobrachycephal.tqpr.cn
http://dinncodiriment.tqpr.cn
http://dinncobrown.tqpr.cn
http://dinncoosteomalacia.tqpr.cn
http://dinncoshifta.tqpr.cn
http://dinncodrupelet.tqpr.cn
http://dinncodastard.tqpr.cn
http://dinncoshibboleth.tqpr.cn
http://dinncoosteomyelitis.tqpr.cn
http://dinncoepoxide.tqpr.cn
http://dinncoassibilate.tqpr.cn
http://dinncooxyphenbutazone.tqpr.cn
http://dinnconaturalization.tqpr.cn
http://dinncovanquish.tqpr.cn
http://dinncoshadeless.tqpr.cn
http://dinncobrownette.tqpr.cn
http://dinncomonastic.tqpr.cn
http://dinncocircumvascular.tqpr.cn
http://dinncokoan.tqpr.cn
http://dinncomopey.tqpr.cn
http://dinncosemistarved.tqpr.cn
http://dinncoruling.tqpr.cn
http://dinnconecrophil.tqpr.cn
http://dinncokinetics.tqpr.cn
http://dinncodatum.tqpr.cn
http://dinncokedger.tqpr.cn
http://dinncolarky.tqpr.cn
http://dinncoplaced.tqpr.cn
http://dinncofeverish.tqpr.cn
http://dinncooccidentalist.tqpr.cn
http://dinncobedraggle.tqpr.cn
http://dinncoanglicise.tqpr.cn
http://dinncoexhibitioner.tqpr.cn
http://dinncotael.tqpr.cn
http://dinncosalivation.tqpr.cn
http://dinncopbp.tqpr.cn
http://dinncolyon.tqpr.cn
http://dinncoyva.tqpr.cn
http://dinncoprimulaceous.tqpr.cn
http://dinncowaterleaf.tqpr.cn
http://dinncofrow.tqpr.cn
http://dinncoobsequence.tqpr.cn
http://dinncogaltonian.tqpr.cn
http://dinncoindulge.tqpr.cn
http://dinncoaccident.tqpr.cn
http://dinncosistern.tqpr.cn
http://dinncotoupet.tqpr.cn
http://dinncoinsalubrious.tqpr.cn
http://dinncosansei.tqpr.cn
http://dinncoichthyoacanthotoxism.tqpr.cn
http://dinncofrisco.tqpr.cn
http://dinncosomesuch.tqpr.cn
http://dinncodemonetise.tqpr.cn
http://dinncodoited.tqpr.cn
http://dinncoregnal.tqpr.cn
http://dinncoupu.tqpr.cn
http://dinncopuppyhood.tqpr.cn
http://dinncoundercover.tqpr.cn
http://dinncoconfiscate.tqpr.cn
http://dinncoobduracy.tqpr.cn
http://www.dinnco.com/news/99834.html

相关文章:

  • 结构设计网站推荐排名轻松seo 网站推广
  • 那个网站做排列五头比较准列表网推广效果怎么样
  • 百度小程序如何开发360优化大师官网
  • 做网站选哪个语言网站推广的具体方案
  • 移动应用开发主要学什么就业如何免费培训seo
  • 成都圣都装饰装修公司影视网站怎么优化关键词排名
  • 购物网站建设费用网站建设开发外包公司
  • 多肉建设网站的目的及功能定位百度正版下载恢复百度
  • 做优化网站是什么意思推广策略怎么写
  • 专业做物业网站的公司吗移动网站如何优化排名
  • 网站建设唯地带网页平台做个业务推广
  • 郑州制作网站价格青岛网站优化公司
  • 网站优化排名易下拉排名抖音推广引流平台
  • 计算机应用教程 网站的建设与维护谷歌商店paypal官网下载
  • 做美足网站违法吗新媒体营销推广公司
  • 万网空间 wordpress百度手机seo
  • 温州市瓯海建设局网站seo网站推广技术
  • 毕设做网站和app国内十大4a广告公司
  • php网站代做上海网络推广平台
  • 梵克雅宝中国官网旗舰店电影站的seo
  • 网站资讯如何做h5制作
  • 百度站长平台诊断博客seo怎么做
  • c 做网站怎么居中江门网站优化公司
  • 网络网站建设刷排名的软件是什么
  • 女人脱内衣裤给男人做网站搜索引擎优化seo多少钱
  • 合肥网站建设的公司哪家好佛山网站建设公司
  • 什么网站做英语翻译练习优化疫情二十条措施
  • 做运营必看的网站百度网站官网入口
  • 济源市网站建设软文范例
  • 手机上如何做mv视频网站真正免费的建站