应该如何修改
来源:4-16 自由编程
Aurora_Meteor
2020-05-23 10:42:30
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./vue.js"></script>
<style>
#container {
border: 1px solid #eee;
display: inline-block;
margin: 0 auto;
}
span {
padding: 20px 10px;
}
p {
text-align: center;
}
.active {
background: #eee;
}
</style>
</head>
<body>
<div id="app">
</div>
<script>
Vue.component('s1', {
template: '<p>前端工程师</p>'
})
Vue.component('s2', {
template: '<p>Java工程师</p>'
})
Vue.component('s3', {
template: '<p>软件测试工程师</p>'
})
var vm = new Vue({
el: '#app',
data: {
list: [
'前端工程师',
'Java工程师',
'软件测试工程师'
],
idx: ''
},
template: `
<div>
<div id="container">
<span v-for="(item,index) of list"
@click="handle(index)"
:class="index==idx?'active':''">
{{item}}
</span>
</div>
<component :is="'s'+(idx+1)"></component>
</div>
`,
methods: {
handle(index) {
this.idx = index;
}
}
})
</script>
</body>
</html>
上面的选项卡整体不能居中,选项卡的内容超出了包裹的容器,应该怎么改?
另外是否还有其他问题?
2回答
同学你好,逻辑是没有问题的。建议修改样式:

如果我的回答帮到了你,欢迎采纳,祝学习愉快~
好帮手慕码
2020-05-23
同学你好,是的。通过设置宽度、margin是最简单的实现居中的方式。
祝学习愉快~
相似问题
回答 1
回答 1