Javascript 使用:class应用类
我已经看过文档了,但我仍然不知道如何使用它,基本上一开始我只是想用vue.js显示一个特定的类,我以后想动态更改它,我只是想设置该类的默认行为,所以我做了如下操作: html javascriptJavascript 使用:class应用类,javascript,html,css,vue.js,vuejs2,Javascript,Html,Css,Vue.js,Vuejs2,我已经看过文档了,但我仍然不知道如何使用它,基本上一开始我只是想用vue.js显示一个特定的类,我以后想动态更改它,我只是想设置该类的默认行为,所以我做了如下操作: html javascript new Vue({ el: '#monsterGame', data: { incrementMonster: 0, incrementYou: 0, progressMonster: { 'width': '10
new Vue({
el: '#monsterGame',
data: {
incrementMonster: 0,
incrementYou: 0,
progressMonster: {
'width': '100px',
'background-color': 'green',
'height': '50px'
},
progressYou: {
'width': '100px',
'background-color': 'green',
'height': '50px'
}
}
})
我需要在css中附加它吗?我基本上希望在css中添加一个类,并通过在javascript端的数据上创建的对象动态地更改它,但我看不到任何东西:S,我做错了什么?您正在使用,但您的参数不是类名,而是样式规范
而且,CSS中有不必要的引号
newvue({
el:“#怪物游戏”,
数据:{
递增怪物:0,
递增你:0,
类名:'progressMonster'
},
方法:{
toggleClass:函数(){
this.className=this.className=='progressMonster'?'progressYou':'progressMonster';
}
}
})
.progressYou{
宽度:100px;
颜色:白色;
背景颜色:绿色;
高度:50px;
}
.怪物{
颜色:黑色;
宽度:100px;
背景颜色:浅蓝色;
高度:50px;
}
你
自闭症
自闭症
转换
您正在使用,但您的参数不是类名,而是样式规范
而且,CSS中有不必要的引号
newvue({
el:“#怪物游戏”,
数据:{
递增怪物:0,
递增你:0,
类名:'progressMonster'
},
方法:{
toggleClass:函数(){
this.className=this.className=='progressMonster'?'progressYou':'progressMonster';
}
}
})
.progressYou{
宽度:100px;
颜色:白色;
背景颜色:绿色;
高度:50px;
}
.怪物{
颜色:黑色;
宽度:100px;
背景颜色:浅蓝色;
高度:50px;
}
你
自闭症
自闭症
转换
.progressYou{
width: '100px';
background-color: 'green';
height: '50px';
}
.progressMonster{
width: '100px';
background-color: 'green';
height: '50px';
}
new Vue({
el: '#monsterGame',
data: {
incrementMonster: 0,
incrementYou: 0,
progressMonster: {
'width': '100px',
'background-color': 'green',
'height': '50px'
},
progressYou: {
'width': '100px',
'background-color': 'green',
'height': '50px'
}
}
})