当前位置:网站首页>03_el与data的两种写法
03_el与data的两种写法
2022-07-17 00:06:00 【id不存在。】
el与data的两种写法
data与el的两种写法
el有两种写法:
1.new Vue时候配置el属性
2.先创建vue实例,随后再通过vm.$mount('root')指定el的值
data有两种写法:
1.对象式
2.函数式
目前哪种写法都可以,学习到组件时,data必须用函数式
注意:由vue管理的函数,一定不要写箭头函数,一旦写了箭头函数,this就不再是vue实例了
<body>
<div id="root">
<h1>你好,{
{name}}</h1>
</div>
</body>
<script type="text/javascript">
Vue.config.productionTip = false //阻止 vue 在启动时生成生产提示。
//el的两种写法
/* const v = new Vue({
//el:'#root', //第一种写法
data:{
name:'尚硅谷'
}
})
console.log(v)
v.$mount('#root') //第二种写法 */
//data的两种写法
new Vue({
el: '#root',
//data的第一种写法:对象式
/* data:{
name:'尚硅谷'
} */
//data的第二种写法:函数式
data() {
console.log('@@@', this) //此处的this是Vue实例对象
return {
name: '尚硅谷'
}
}
})
</script>边栏推荐
- (6) Test command
- Vue项目部署,清理缓存
- 分布式之数据库和缓存双写一致性方案解析(转载)
- Array Operations - judgment, de duplication, consolidation, expansion
- JS get the suffix format of a file name
- uni-app微信小程序——商城(6)——我的主页
- extern和static的区别
- 今天的码农女孩总结了jQuery处理缓存的方法和事件委托方法的区别的笔记
- Cve-2022-34265 Django extract & TRUNC SQL injection vulnerability recurrence
- uni-app微信公众号(5)——新增、修改地址
猜你喜欢

uniapp中text-indent不起作用,uniapp首行缩进不管用如何解决?

Record once easy_ SQL Stack Injection

服务器如何安装宝塔面板?(宝塔面板安装教程)

How to modify the color of a line of text in the elemtnui table (elemtnui table modifies the color of a line of text)
![[elementui El date picker date selector, the end time must not be earlier than the start time, and only the date of the specified number of days from the start time can be selected]](/img/73/af7ca3f670ffee18081b9ca6a9ccf6.png)
[elementui El date picker date selector, the end time must not be earlier than the start time, and only the date of the specified number of days from the start time can be selected]

Page layout - three column layout solution

everything搜索不到startup_lpc11x.s文件

uni-app微信小程序——商城(6)——我的主页

js获取一个文件名的后缀格式

使用bat自动执行cmd命令(多个命令或单个命令)
随机推荐
(六)test命令
(10)文件包含
object-fit:cover; It doesn't work in the applet. How to deal with the deformation of the applet image
tp-watermark.js网页添加水印插件
记一次用canvas做出腾讯云首页banner流光效果的经历
【ElenmentUI el-date-picker日期选择器,结束时间不得早于开始时间,且只能选择距开始时间指定天数的日期】
2022年暑假ACM热身练习2(总结)
JS get the suffix format of a file name
uni canvas截取图片
computed和watch、watchEffect
Summary of Applied Cryptography
列表懒加载和图片懒加载
【专题】用ST表解决RMQ刷题总结
分布式之数据库和缓存双写一致性方案解析(转载)
Day11 serializer
今天的码农女孩做了关于呼吸灯的练习、受控组件和高阶组件的简答题
解决小程序自定义底部菜单切换闪动
Uni app wechat applet - Mall (3) - Mall Homepage
Cve-2022-34265 Django extract & TRUNC SQL injection vulnerability recurrence
(八)Shell函数