Vue.component('model', { props: ['list', 'isactive'], template: `<div class="overlay" v-show="isactive"> <div class="con"> <h4 style="text-align: center">新增 | 修改</h4> <div class="content" > <div style="margin:10px auto;" v-for="(value, key) of modifylist"> <div class="item_name" v-if="key!='uid'&&key!='time'"> <span v-if="key=='id'">编号</span> <span v-else-if="key=='user_name'">用户名</span> <span v-else-if="key=='user_passwd'">密码</span> <span v-else-if="key=='uid'">识别码</span> <span v-else-if="key=='role'">角色</span> <span v-else-if="key=='note'">备注</span> <span v-else-if="key=='time'">时间</span> <span v-else>{{ key }}</span> </div> <input class="item_value" type="text" v-model="modifylist[key]" v-if="key!='uid'&&key!='time'" > <div style="clear: both;"></div> </div> <div style="margin: 20px 30px;"> <input class="item_name" style="font-size: 18px;text-align: center;" type="button" @click="changeActive" value="取消"> <input class="item_value" style="font-size: 18px;text-align: center;" type="button" @click="modify" value="保存"> </div> </div> </div> </div>`, computed: { modifylist() { return JSON.parse(JSON.stringify(this.list)); } }, methods: { changeActive() { this.$emit('change'); }, modify() { this.$emit('modify', this.modifylist); } } });

时间: 2023-10-17 20:05:17 浏览: 53
这是一个 Vue.js 的组件,用于展示一个弹窗,可以用于新增或者修改数据。其中,props 接收两个参数:list 和 isactive,list 是一个对象数组,用于展示数据;isactive 是一个布尔值,用于控制弹窗的显示与隐藏。模板中使用了 v-show 指令控制弹窗的显示与隐藏。computed 属性中定义了一个计算属性 modifylist,用于获取 list 的深拷贝,方便修改数据时不影响原数据。methods 中定义了两个方法:changeActive 和 modify,分别用于关闭弹窗和保存修改后的数据。其中,changeActive 使用了 $emit 方法向父组件传递事件,从而实现关闭弹窗的功能;modify 方法也使用了 $emit 方法向父组件传递修改后的数据。
相关问题

<template> <div class="container"> <div class="detail-wrap"> <img :src="imgSrc" alt=""> <div> <h1>{{ msg }}</h1> <p><span>¥</span><span>{{ price }}</span></p> <div><input type="number" v-model="num"></div> <button v-on:click="addToCart">加入购物车</button> </div> </div> </div> </template>这是GoodsDetail01,<template> <div class="container"> <div class="detail-wrap"> <img :src="imgSrc" alt=""> <div> <h1>{{ msg }}</h1> <p><span>¥</span><span>{{ price }}</span></p> <div><input type="number" v-model="num"></div> <button v-on:click="addToCart">加入购物车</button> </div> </div> </div> </template>这是GoodsDetail02,这是<template > <div class="product-wrap" > <div class="product" v-for="product in products" :key="product.id" @click="handleClick(product.id)"> <img :src="product.image" alt="" > <div> <span>{{ product.name }}</span> <h4>¥{{ product.price }}</h4> </div> <component :is="currentComponent"></component> </div> </div> </template>这是goodslist商品主页,实现goodslist点击跳转到GoodsDetail01和GoodsDetail02,请用动态组件实现跳转,写出vue.app和goodslist代码

Vue.app代码如下: ```html <template> <div id="app"> <router-view></router-view> </div> </template> <script> export default { name: "App", }; </script> ``` goodslist代码如下: ```html <template> <div> <h2>商品列表</h2> <div class="product-wrap"> <div class="product" v-for="product in products" :key="product.id" @click="handleClick(product.id)"> <img :src="product.image" alt=""> <div> <span>{{ product.name }}</span> <h4>¥{{ product.price }}</h4> </div> </div> </div> <component :is="currentComponent"></component> </div> </template> <script> import GoodsDetail01 from "./GoodsDetail01.vue"; import GoodsDetail02 from "./GoodsDetail02.vue"; export default { name: "GoodsList", components: { GoodsDetail01, GoodsDetail02, }, data() { return { products: [ { id: 1, name: "商品1", price: 100, image: "https://via.placeholder.com/150", }, { id: 2, name: "商品2", price: 200, image: "https://via.placeholder.com/150", }, ], currentComponent: "", }; }, methods: { handleClick(id) { if (id === 1) { this.currentComponent = "GoodsDetail01"; } else if (id === 2) { this.currentComponent = "GoodsDetail02"; } }, }, }; </script> ```

<div class="product-specs"> <h3>规格</h3> <div class="spec-list"> <div v-for="(spec, index) in product.specs" :key="index" :class="{ 'spec-item': true, 'active': product.selectedSpecIndex === index }" @click="selectSpec(index)"> <span class="spec-name">{{ spec.name }}</span> <span class="spec-value">{{ spec.value }}</span> </div> </div>

这段代码是一个 Vue.js 组件,用于渲染产品规格列表。在该组件中,使用了 v-for 指令对规格列表进行遍历,使用 :key 绑定了每个规格的索引,使用 :class 绑定了样式类名,以便根据选中状态添加/移除样式。同时,使用 @click 绑定了选中规格的事件处理程序。在事件处理程序中,会将选中的规格索引更新到组件的数据中,以便在界面中展示当前选择的规格。

相关推荐

<script setup> import VueUploadComponent from "vue-upload-component"; import { upload } from "@/api/conf"; const isUploading = ref(false); const allowedExtensions = ref(["jpg", "jpeg", "png", "gif"]); const maxFileSize = ref(10 * 1024 * 1024); const uploadedFiles = ref([]); function handleInputFilter(uploadData) { // 文件过滤器 if (uploadData.file.type.indexOf("image/") !== 0) { return Promise.reject("只能上传图片文件"); } return Promise.resolve(uploadData); } function handleBeforeUpload(uploadData) { // 开始上传前的回调 this.isUploading = true; return uploadData; } function handleUploading(uploadData) { console.log("uploading", uploadData.progress); } function handleUploadSuccess(uploadData) { console.log("success", uploadData.url); this.uploadedFiles.push({ id: uploadData.response.id, name: uploadData.file.name, size: uploadData.file.size, url: uploadData.response.url, }); this.isUploading = false; } function handleUploadError(uploadData) { console.error("error", uploadData.error); this.isUploading = false; } function fileSize(size) { if (size < 1024) { return size + "B"; } else if (size < 1024 * 1024) { return (size / 1024).toFixed(2) + "KB"; } else { return (size / 1024 / 1024).toFixed(2) + "MB"; } } function deleteFile(index) { this.uploadedFiles.splice(index, 1); } </script> <template> <vue-upload-component :http-client="upload" :multiple="true" :accept="'image/*'" :extensions="allowedExtensions" :maxSize="maxFileSize" @input-filter="handleInputFilter" @before-upload="handleBeforeUpload" @uploading="handleUploading" @upload-success="handleUploadSuccess" @upload-error="handleUploadError" > <template v-slot:default> 点击上传 上传中... </template> </vue-upload-component> {{ file.name }} {{ fileSize(file.size) }} 删除 </template> 优化一下

最新推荐

recommend-type

vue里面v-bind和Props 利用props绑定动态数据的方法

今天小编就为大家分享一篇vue里面v-bind和Props 利用props绑定动态数据的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

2024年设备创新与市场拓展成果.pptx

行业报告
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

从键盘输入一段英文字符串,其中包含多个字母‘h',请编写程序利用正则表达式,将英文字符串中的’h'全部改为‘H’

好的,我可以帮您解决这个问题。 您可以使用 Python 编写一个程序来实现这个功能。具体步骤如下: 1. 首先导入 re 模块,这个模块是 Python 中用于处理正则表达式的模块。 2. 然后定义一个包含英文字符串的变量,例如: text = "This is a string containing multiple h's." 3. 接下来,使用 re.sub() 方法来进行替换操作。re.sub() 方法的第一个参数是正则表达式,第二个参数是替换的字符或字符串,第三个参数是被替换的字符串。在这个例子里,我们需要将所有的小写字母 h 替换成大写字母 H,所以正则表达式可以写成
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

MATLAB柱状图在数据分析中的作用:从可视化到洞察

![MATLAB柱状图在数据分析中的作用:从可视化到洞察](https://img-blog.csdnimg.cn/img_convert/1a36558cefc0339f7836cca7680c0aef.png) # 1. MATLAB柱状图概述** 柱状图是一种广泛用于数据可视化的图表类型,它使用垂直条形来表示数据中不同类别或组别的值。在MATLAB中,柱状图通过`bar`函数创建,该函数接受数据向量或矩阵作为输入,并生成相应的高度条形。 柱状图的优点在于其简单性和易于理解性。它们可以快速有效地传达数据分布和组别之间的比较。此外,MATLAB提供了广泛的定制选项,允许用户调整条形颜色、
recommend-type

MySQL 什么情况下不会使用到索引

MySQL 不会使用索引的情况主要包括: 1. 查询的数据量太少,全表扫描比使用索引更快; 2. 使用了函数或表达式对索引字段进行运算; 3. 对索引字段进行了类型转换; 4. 索引列上出现了函数或者运算符; 5. 查询语句中使用了 OR 连接多个条件; 6. 查询条件中有 NULL 值; 7. 数据表的数据量过于庞大,索引失去了优势。