{{xxx}}—绑定数据
V-bind:title=”xxx”—绑定属性
非动态绑定!!!
数据从后台循环出来,请求api接口获取:
注释无法编写,格式改为html.
Vue官网: https://cn.vuejs.org
样式绑定:
动态改变box的宽度:
左右滑动效果:
<template>
<div id="app">
<!--文本绑定-->
<hr>
<div v-bind:title="title">111111</div>
<div :title="title">222222</div>
<hr>
</template>
<script>
export default {
//name:"app",
data(){
return{
title:'这是一个文本'
}
}
</script>
<style>
#app {
font-family:serif;
font-size:50px;
font-style:bold;
text-align: center;
color: #f32a10;
margin-top: 60px;
}
</style>
静态资源绑定:
<template>
<div id="app">
<!--资源绑定-->
<img v-bind:src="url"/>
<img :src="url"/>
</template>
<script>
export default {
//name:"app",
data(){
return{
url: 'http://localhost:8081/static/image/1.jpg'
}
}
</script>
<style>
#app {
font-family:serif;
font-size:50px;
font-style:bold;
text-align: center;
color: #f32a10;
margin-top: 60px;
}
</style>
<template>
<div id="app">
<!--图片遍历-->
<div v-for="(item,index) in images" :key="index">
<img :src="item.src" alt/>
</div>
</template>
<script>
export default {
// name:"app",
data(){
return{
images:[
{'src':'http://localhost:8081/static/image/1.jpg'},
{'src':'http://localhost:8081/static/image/1.jpg'},
{'src':'http://localhost:8081/static/image/1.jpg'},
{'src':'http://localhost:8081/static/image/1.jpg'},
]
}
}
}
</script>
<style>
#app {
font-family:serif;
font-size:50px;
font-style:bold;
text-align: center;
color: #f32a10;
margin-top: 60px;
}
</style>
<template>
<div id="app">
<hr>
{{hs}}
<hr>
<div v-html='hs'></div>
</template>
<script>
export default {
// name:"app",
data(){
return{
hs:'<h2>这是一个html标签!!!</h2>'
}
}
}
</script>
<style>
#app {
font-family:serif;
font-size:50px;
font-style:bold;
text-align: center;
color: #f32a10;
margin-top: 60px;
}
</style>
<template>
<div id="app">
<hr>
<div v-text="title"></div>
</template>
<script>
// import HelloWorld from './components/HelloWorld.vue'
export default {
// name:"app",
data(){
return{
title:'这是一个文本',
}
}
}
</script>
<style>
#app {
font-family:serif;
font-size:50px;
font-style:bold;
text-align: center;
color: #f32a10;
margin-top: 60px;
}
</style>
<template>
<div id="app">
<hr>
<div v-for="item in list" :key="item">
{{item}}
</div>
</template>
<script>
export default {
// name:"app",
data(){
return{
list:['a','b','c','d']
}
}
}
</script>
<style>
#app {
font-family:serif;
font-size:50px;
font-style:bold;
text-align: center;
color: #f32a10;
margin-top: 60px;
}
</style>
<template>
<div id="app">
<hr>
<div v-for="item in list" :key="item">
<!--默认为蓝色;flag为true时为蓝色-->
<div v-bind:class="{'red':!flag,'blue':flag}">
{{item}}
</div>
</div>
</template>
<script>
// import HelloWorld from './components/HelloWorld.vue'
export default {
// name:"app",
data(){
return{
list:['a','b','c','d'],
flag:false
}
}
}
</script>
<style>
#app {
font-family:serif;
font-size:50px;
font-style:bold;
text-align: center;
color: #4110f3;
margin-top: 60px;
}
.blue {
font-family:serif;
font-size:50px;
font-style:bold;
text-align: center;
color: #f37e10;
margin-top: 60px;
}
</style>
<template>
<div id="app">
<hr>
<div v-for="(item,key) in list" :key="item"
:class="{'red':key==0,'blue':key==1,'yellow':key==2,'green':key==3}">
{{key}}--{{item}}
</div>
</template>
<script>
export default {
// name:"app",
data(){
return{
list:['a','b','c','d']
}
}
}
</script>
<style>
.blue {
font-family:serif;
font-size:50px;
font-style:bold;
text-align: center;
color: #5616ec;
margin-top: 60px;
}
.red {
font-family:serif;
font-size:50px;
font-style:bold;
text-align: center;
color: #ec5a16;
margin-top: 60px;
}
.yellow {
font-family:serif;
font-size:50px;
font-style:bold;
text-align: center;
color: #9aec16;
margin-top: 60px;
}
.green {
font-family:serif;
font-size:50px;
font-style:bold;
text-align: center;
color: #629413;
margin-top: 60px;
}
</style>
<template>
<div id="app">
<!--动态改变区域大小-->
<div class="box" v-bind:style="{'width':divWidth+'px','height':divHeight+'px'}">
box
</div>
</template>
<script>
export default {
// name:"app",
data(){
return{
divWidth:600,
divHeight:600
}
}
}
</script>
<style>
.box {
width:200px;
height: 300px;
background-color: #ec5a16;
text-align: center;
line-height: 300px;
}
</style>
VUE 中图片引入和折叠效果
<template>
<div class="about">
<div class="innerbox">
<div class="toppart">
<div class="box_margin"></div>
<div class="imgbox">
<img src="~@/assets/images/jianjie.png" alt />
</div>
<div class="rightTitle">
<div class="training_center">
<span>武汉理工大学工程训练中心 — </span>
<span>简介</span>
</div>
</div>
</div>
<div class="aboutContent">
<p>武汉理工大学工程训练中心是学校重要的大学生实践教学基地,拥有实践教学场地面积13500平米,教学仪器设备818台/套,设备总值近1600万元。中心依托于机械工程学科,紧密结合我校为“建材、 交通、汽车”三大行业服务的办学特色,建立具有行业特色的大工程背景环境的机械工程综合实践教学平台,面向全校43个本科专业学生开展机械制造基础认知实训、机械制造工程实训及机械设计及制造综合创新训练。</p>
<p>中心根据学生专业特点,采用分层次、模块化教学方法,构建具有24个训练项目模块的工程实践教学体系,每年接纳约7000名学生进行工程实践训练,培养具有较强工程综合能力及创新能力的应用型工程技术人才。中心积极推进教学改革,在课程建设、教学改革、实践基地建设及大学生综合创新训练方面取得了丰硕成果:“机械制造工程实训” 课程获湖北省精品课程; "机械类人才工程能力的培养模式的研究与实践”获湖北省优秀教学成果一等奖;中心于2008年被教育部批准立项为国家级实验教学示范中心建设单位,2015年通过教育部验收正式批准为国家级实验教学示范中心;中心积极开展大学生综合创新训练,建成湖北省机电工程综合设计与制造大学生创新活动基地。武汉理工大学工程训练中心将按照国家级实验教学示范中心建设要求,继续深化实践教学改革,为培养“适应能力强,实干精神强,创新意识强”的高素质工程技术人才做出贡献。</p>
<div class="box_image_show" ref="carouseImg">
<van-swipe :loop="false" :show-indicators="false" :autoplay="2000">
<van-swipe-item v-for="(item,index) in img" :key="index">
<img :src="item.src" alt />
</van-swipe-item>
</van-swipe>
</div>
</div>
</div>
</div></template>
<script>
import Viewer from "viewerjs";
import "viewerjs/dist/viewer.css";
export default {
data() {
return {
centerDialogVisible: false,
img: [
{ src: require("@/assets/images/jianjie1.jpg") },
{ src: require("@/assets/images/jianjie2.jpg") },
{ src: require("@/assets/images/jianjie3.jpg") },
{ src: require("@/assets/images/jianjie4.jpg") },
{ src: require("@/assets/images/jianjie5.jpg") },
{ src: require("@/assets/images/jianjie6.jpg") },
{ src: require("@/assets/images/jianjie7.jpg") },
{ src: require("@/assets/images/jianjie8.jpg") },
{ src: require("@/assets/images/jianjie9.jpg") }
]
};
},
mounted() {
this.$nextTick(() => {
new Viewer(this.$refs.carouseImg);
});
},
methods: {}
};</script>
/******************后台折叠效果************************/<template><el-container class="layout-container">
<el-aside class="aside" :width='isCollapse?"64px":"200px"'>
<app-aside class="app-aside" :isCollapse="isCollapse"></app-aside>
</el-aside>
<el-container>
<el-header class="header">
<div class="header-left" style="cursor: pointer;">
<!--<i :class="{'el-icon-s-fold':isCollapse, 'el-icon-s-unfold': !isCollapse}" @click="BtnClickTrueAndFalse"></i>-->
<i :class="isCollapse?'el-icon-s-fold':'el-icon-s-unfold'" @click="BtnClickTrueAndFalse"></i>
<span>直播后台系统</span>
</div>
<el-dropdown>
<div class="header_right">
<img :src="userInfo.photo">
<span> {{ userInfo.name }} <i class="el-icon-arrow-down el-icon--right"></i></span>
</div>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item>
<i class="iconfont iconpersonal"></i>
个人设置
</el-dropdown-item>
<el-dropdown-item @click.native="BtnOut">
<i class="iconfont iconout"></i>
退出
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</el-header>
<el-main class="main">
<!--路由出口-->
<router-view></router-view>
</el-main>
</el-container></el-container></template>
<script>
import AppAside from "./components/aside";
import {
getUserProfile
} from "@/api/user";
import {
log
} from "util";
export default {
name: "LayouIndex",
data() {
return {
userInfo: {},
isCollapse: false //侧边菜单栏的展开状态
};
},
components: {
AppAside
},
created() {
this.loadUserProfile();
},
methods: {
loadUserProfile() {
getUserProfile().then(res => {
// console.log(res)
this.userInfo = res.data.data;
});
},
BtnOut() {
this.$confirm("确认退出?")
.then(_ => {
window.sessionStorage.removeItem("token");
this.$router.push("/login");
done();
})
.catch(_ => {});
},
BtnClickTrueAndFalse() {
this.isCollapse = !this.isCollapse;
}
}
};
</script>