Vue2+ElementUI Demo

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Vue2+ElementUI Demo</title>
		<!-- <link rel="stylesheet" href="element/index.css"> -->
		<link rel="stylesheet" href="https://unpkg.com/element-ui@2.15.13/lib/theme-chalk/index.css">
	</head>

	<body>
		<div id="app">
			<el-input v-model="item.code" placeholder="请输入编码"></el-input>
			<el-input v-model="item.name" placeholder="请输入名称"></el-input>
			<el-button @click="test" type="primary">默认按钮</el-button>
		</div>
		<!-- <script src="vue.js"></script> -->
		<!-- <script src="element/index.js"></script> -->
		<script src="https://unpkg.com/vue@2.7.14/dist/vue.js"></script>
		<script src="https://unpkg.com/element-ui@2.15.13/lib/index.js"></script>
		<script>
			new Vue({
				el: '#app',
				data() {
					return {
						item: {
							code: '',
							name: ''
						}
					};
				},
				methods: {
					test() {
						let _this = this;
						console.log(_this.item);
					}
				},
				mounted() {
					console.log('mounted');
				},
				created() {
					console.log('created');
				},

			})
		</script>
	</body>
</html>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以通过使用`el-upload`组件来实现多图片上传,然后利用`el-carousel`组件展示多张图片。 以下是一个简单的示例代码: ```html <template> <div> <el-upload class="upload-demo" action="/upload" :on-success="handleSuccess" :before-upload="beforeUpload" :file-list="fileList" multiple list-type="picture-card" > <i class="el-icon-plus"></i> </el-upload> <el-carousel :interval="5000"> <el-carousel-item v-for="(file, index) in fileList" :key="index"> <img :src="file.url" class="carousel-image"> </el-carousel-item> </el-carousel> </div> </template> <script> export default { data() { return { fileList: [] }; }, methods: { handleSuccess(response, file, fileList) { // 上传成功后将图片信息存入fileList中 this.fileList = fileList.map(file => { return { url: URL.createObjectURL(file.raw), name: file.name }; }); }, beforeUpload(file) { // 控制上传文件类型和大小 const isJPG = file.type === 'image/jpeg'; const isPNG = file.type === 'image/png'; const isLt2M = file.size / 1024 / 1024 < 2; if (!isJPG && !isPNG) { this.$message.error('上传图片只能是 JPG/PNG 格式!'); return false; } if (!isLt2M) { this.$message.error('上传图片大小不能超过 2MB!'); return false; } return true; } } }; </script> <style scoped> .upload-demo { margin-bottom: 20px; } .carousel-image { width: 100%; height: 400px; object-fit: cover; } </style> ``` 在示例中,我们使用`el-upload`组件来实现图片上传,`multiple`属性可以让用户选择多张图片。`before-upload`方法可以控制上传文件的类型和大小。`handleSuccess`方法在上传成功后将图片信息存入`fileList`中。 最后,我们使用`el-carousel`组件来展示所有上传的图片。在`v-for`循环中,使用`el-carousel-item`包裹每一张图片,`img`标签的`src`属性绑定当前图片的URL。通过CSS样式控制图片的宽高比例和填充方式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值