bus: //vue原型链挂载总线 Vue.prototype.bus = new Vue(); //子组件发送数据 this.bus.$emit("change",data); //子组件接收数据 this.bus.$on("change",function(data){ }) vue中$emit与$on var Event = new Vue(); 相当于又new了一个vue实例,Event中含有vue的全部方法; Event.$emit('msg',this.msg); 发送数据,第一个参数是发送数据的名称,接收时还用这个名字接收,第二个参数是这个数据现在的位置; Event.$on('msg',function(msg){ 接收数据,第一个参数是数据的名字,与发送时的名字对应,第二个参数是一个方法,要对数据的操作 /这里是对数据的操作 }) 例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>孙三峰--博客园</title> <script type="text/javascript" src="js/vue2.0.3.js" ></script> <script type="text/javascript"> //准备一个空的实例对象 var Event = new Vue(); var A={ template:` <div style="border: 1px solid red; margin-bottom: 10px; width: 300px;"> <h4>A组件</h4> <p>{{a}}</p> <input type="button" value="把A数据给C" @click="send" /> </div> `, data(){ return { a:'我是A里面的数据' } }, methods:{ send(){ //A发送数据 Event.$emit('a-msg',this.a); } } }; var B={ template:` <div style="border: 1px solid green; margin-bottom: 10px; width: 300px;"> <h4>B组件</h4> <p>{{b}}</p> <input type="button" value="把B数据给C" @click="send" /> </div> `, data(){ return { b:'我是B里面的数据' } }, methods:{ send(){ Event.$emit('b-msg',this.b); } } }; var C={ template:` <div style="border: 1px dotted green; margin-bottom: 10px;width: 300px;"> <h4>我是C组件,我在坐等接收数据</h4> <p>{{a}}</p> <p>{{b}}</p> </div> `, data(){ return{ a:'', b:'' } }, mounted(){ //两种接收的方式 var _this = this; Event.$on('a-msg',function(a){ _this.a=a; }); Event.$on('b-msg',function(b){ this.b = b; }.bind(this)) } }; window.onload=function(){ new Vue({ el:'#box', data:{ }, components:{ 'com-a':A, 'com-b':B, 'com-c':C } }) } </script> </head> <body> <div id="box"> <com-a></com-a> <com-b></com-b> <com-c></com-c> </div> </body> </html> |
效果图: from:https://www.cnblogs.com/wang-sai-sai/p/11158770.html
View Details导致该问题的原因在于没有配置curl.cainfo,该配置位于php.ini中。 解决方案: 1)下载cacert.pem https://curl.haxx.se/ca/cacert.pem 2)配置php.ini [curl] ; A default value for the CURLOPT_CAINFO option. This is required to be an ; absolute path. curl.cainfo = 【你的绝对路径】 ———————————————— 版权声明:本文为CSDN博主「loophome」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/loophome/java/article/details/83112364
View Details
1 2 3 4 5 6 7 8 9 10 11 12 |
/// <summary> /// get ip /// </summary> /// <returns></returns> public static string GetIp() { var context = HttpContext.Current; return context.Request.ServerVariables["HTTP_X_REAL_IP"] ?? context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? context.Request.ServerVariables["REMOTE_ADDR"] ?? "unknow"; } |
View Details
public HttpResponseMessage getHtml() { string uri = "http://docs.google.com/gview?embedded=true&url=www.pdf995.com/samples/pdf.pdf"; WebClient wc = new WebClient(); Stream resStream = wc.OpenRead(uri); StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default); string ContentHtml = sr.ReadToEnd(); var response = new HttpResponseMessage(); response.Content = new StringContent(ContentHtml); response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html"); return response; } ———————————————— 版权声明:本文为CSDN博主「小咪蜂」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/xiaomifengmaidi1/java/article/details/84665109
View DetailsASP.NET Web API实现简单的文件下载与上传。首先创建一个ASP.NET Web API项目,然后在项目下创建FileRoot目录并在该目录下创建ReportTemplate.xlsx文件,用于下面示例的使用。 1、文件下载 示例:实现报表模板文件下载功能。 1.1 后端代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/// <summary> /// 下载文件 /// </summary> [HttpGet] public HttpResponseMessage DownloadFile() { string fileName = "报表模板.xlsx"; string filePath = HttpContext.Current.Server.MapPath("~/") + "FileRoot\\" + "ReportTemplate.xlsx"; FileStream stream = new FileStream(filePath, FileMode.Open); HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StreamContent(stream); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = HttpUtility.UrlEncode(fileName) }; response.Headers.Add("Access-Control-Expose-Headers", "FileName"); response.Headers.Add("FileName", HttpUtility.UrlEncode(fileName)); return response; } |
1.2 前端代码
1 |
<a href="http://localhost:51170/api/File/DownloadFile">下载模板</a> |
2、文件上传 示例:实现上传报表文件功能。 2.1 后端代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/// <summary> /// 上传文件 /// </summary> [HttpPost] public HttpResponseMessage UploadFile() { try { //获取参数信息 HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; HttpRequestBase request = context.Request; //定义传统request对象 string monthly = request.Form["Monthly"]; //获取请求参数:月度 string reportName = request.Form["ReportName"]; //获取请求参数:报表名称 //保存文件 string fileName = String.Format("{0}_{1}.xlsx", monthly, reportName); string filePath = HttpContext.Current.Server.MapPath("~/") + "FileRoot\\" + fileName; request.Files[0].SaveAs(filePath); //返回结果 var result = new HttpResponseMessage { Content = new StringContent("上传成功", Encoding.GetEncoding("UTF-8"), "application/json") }; return result; } catch (Exception ex) { throw ex; }; } |
2.2 前端代码
1 2 3 4 5 6 |
<form action='http://localhost:51170/api/File/UploadFile' method="post" enctype="multipart/form-data"> 报表月份:<input type="text" name="Monthly" value="2018-11" /><br /> 报表名称:<input type="text" name="ReportName" value="财务报表" /><br /> 报表文件:<input type="file" name="file" /><br /> <input type="submit" value="提交" /> </form> |
from:https://blog.csdn.net/pan_junbiao/article/details/84065952
View Details由上可见,MIME_MapTable是所有文件的后缀名所对应的MIME类型的一个String数组: Java代码 final String[][] MIME_MapTable={ //{后缀名,MIME类型} {".3gp", "video/3gpp"}, {".apk", "application/vnd.android.package-archive"}, {".asf", "video/x-ms-asf"}, {".avi", "video/x-msvideo"}, {".bin", "application/octet-stream"}, {".bmp", "image/bmp"}, {".c", "text/plain"}, {".class", "application/octet-stream"}, {".conf", "text/plain"}, {".cpp", "text/plain"}, {".doc", "application/msword"}, {".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}, {".xls", "application/vnd.ms-excel"}, {".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}, {".exe", "application/octet-stream"}, {".gif", "image/gif"}, {".gtar", "application/x-gtar"}, {".gz", "application/x-gzip"}, {".h", "text/plain"}, {".htm", "text/html"}, {".html", "text/html"}, {".jar", "application/java-archive"}, {".java", "text/plain"}, {".jpeg", "image/jpeg"}, {".jpg", "image/jpeg"}, {".js", "application/x-javascript"}, {".log", "text/plain"}, {".m3u", "audio/x-mpegurl"}, {".m4a", "audio/mp4a-latm"}, {".m4b", "audio/mp4a-latm"}, {".m4p", "audio/mp4a-latm"}, {".m4u", "video/vnd.mpegurl"}, {".m4v", "video/x-m4v"}, {".mov", "video/quicktime"}, {".mp2", "audio/x-mpeg"}, {".mp3", "audio/x-mpeg"}, {".mp4", "video/mp4"}, {".mpc", "application/vnd.mpohun.certificate"}, {".mpe", "video/mpeg"}, {".mpeg", "video/mpeg"}, {".mpg", "video/mpeg"}, {".mpg4", "video/mp4"}, {".mpga", "audio/mpeg"}, {".msg", "application/vnd.ms-outlook"}, {".ogg", "audio/ogg"}, {".pdf", "application/pdf"}, {".png", "image/png"}, {".pps", "application/vnd.ms-powerpoint"}, {".ppt", "application/vnd.ms-powerpoint"}, {".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"}, {".prop", "text/plain"}, {".rc", "text/plain"}, {".rmvb", "audio/x-pn-realaudio"}, {".rtf", "application/rtf"}, {".sh", "text/plain"}, {".tar", "application/x-tar"}, {".tgz", "application/x-compressed"}, {".txt", "text/plain"}, {".wav", "audio/x-wav"}, {".wma", "audio/x-ms-wma"}, {".wmv", "audio/x-ms-wmv"}, {".wps", "application/vnd.ms-works"}, {".xml", "text/plain"}, {".z", "application/x-compress"}, {".zip", "application/x-zip-compressed"}, {"", "*/*"} }; ———————————————— 版权声明:本文为CSDN博主「零下忆度」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/sinat_30474567/java/article/details/53411146
View Details在HTML5中新增了postMessage方法,postMessage可以实现跨文档消息传输(Cross Document Messaging),Internet Explorer 8, Firefox 3, Opera 9, Chrome 3和 Safari 4都支持postMessage。 该方法可以通过绑定window的message事件来监听发送跨文档消息传输内容。 1. postMessage是HTML5 XMLHttpRequest Level 2中的API,且是为数不多可以跨域操作的window属性之一,它可用于解决以下方面的问题: a.) 页面和其打开的新窗口的数据传递 b.) 多窗口之间消息传递 c.) 页面与嵌套的iframe消息传递 d.) 上面三个场景的跨域数据传递 2. postMessage用法:
1 |
postMessage(data,origin)方法接受两个参数 |
参数说明: data: html5规范支持任意基本类型或可复制的对象,但部分浏览器只支持字符串,所以传参时最好用JSON.stringify()序列化。 origin: 协议+主机+端口号,也可以设置为"*",表示可以传递给任意窗口,如果要指定和当前窗口同源的话设置为"/"。 举例说明: 两个页面之间进行数据传输,postMessage示例: 我启动了两个ip地址来代表不同域名,页面t_hotnotes_list.html插入如下代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<iframe id="iframe" src="http://10.73.154.73:8088/rbc/t/search_role.html" style="display:none;"></iframe> <script> var iframe = document.getElementById('iframe'); iframe.onload = function() { var data = { name: 'aym', type:'wuhan' }; // 向domain2传送跨域数据 iframe.contentWindow.postMessage(JSON.stringify(data), 'http://10.73.154.73:8088'); }; // 接受domain2返回数据,这边给延迟的原因,因为同步传输时,页面不一定立马拿到数据,所以给延迟 setTimeout(function(){ window.addEventListener('message', function(e) { alert('data from domain2 sss ---> ' + e.data); }, false); },10) </script> |
页面search_role.html插入如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<script> // 接收domain1的数据 window.addEventListener('message', function(e) { console.log(e.data); var data = JSON.parse(e.data); if (data) { data.number = 16; data.age = 89; data.icon = 'sfafdafdafasdf'; // 处理后再发回domain1 window.parent.postMessage(JSON.stringify(data), 'http://10.73.154.72:8088'); } }, false); </script> |
当两个服务启动之后,我们在浏览器中打开页面t_hotnotes_list.html
1 |
http://10.73.154.72:8088/rbc/t/t_hotnotes_list.html |
得到如下图结果,t_hotnotes_list.html得到两个页面的数据 from:https://www.cnblogs.com/yyy6/p/9481671.html
View Details一、简介# 1、postMessage()方法允许来自不同源的脚本采用异步方式进行有限的通信,可以实现跨文本档、多窗口、跨域消息传递 2、postMessage(data,origin)方法接受两个参数: (1)data:要传递的数据,html5规范中提到该参数可以是JavaScript的任意基本类型或可复制的对象,然而并不是所有浏览器都做到了这点儿,部分浏览器只能处理字符串参数,所以我们在传递参数的时候需要使用JSON.stringify()方法对对象参数序列化,在低版本IE中引用json2.js可以实现类似效果, (2)origin:字符串参数,指明目标窗口的源,协议+主机+端口号[+URL],URL会被忽略,所以可以不写,这个参数是为了安全考虑,postMessage()方法只会将message传递给指定窗口,当然如果愿意也可以建参数设置为"*",这样可以传递给任意窗口,如果要指定和当前窗口同源的话设置为"/"; 二、使用# 1、子页面向父页面传递消息 <!-- frame1.html --> <h1>iframe1 page</h1> <script> window.top.postMessage('message from iframe1'); </script> 2、父页面向子页面传递消息
1 2 3 4 5 6 7 8 9 |
<!-- index.html --> <iframe src="http://127.0.0.1:5500/frame1.html" frameborder="1"></iframe> <iframe src="http://127.0.0.1:5500/frame2.html" frameborder="1"></iframe> <script> window.onload = function () { var frame1 = window.frames[0]; frame1.postMessage('message from parentwindow', '*'); } </script> |
1 2 3 4 5 6 7 |
<!-- frame1.html --> <h1>iframe1 page</h1> <script> window.addEventListener('message',function(e){ console.log(e.data) },false) </script> |
from:https://www.cnblogs.com/EricZLin/p/10534537.html
View Detailsproperty 异常处理:http://www.cnblogs.com/dunitian/p/4523006.html#dapper 原来Model是这样滴 修改后是这样滴 注意点:Model里面的Table和Key是Dapper.Contrib.Extensions命名空间下的 成功~ from:https://www.cnblogs.com/dunitian/p/5710467.html
View Details介绍下使用Dapper-Extensions的基本语法 //实体类 DemoEntity entity = new DemoEntity(); //根据实体主键删除 this.Delete<DemoEntity>(entity); //根据主键ID删除 this.Delete<DemoEntity>(1); //增加 this.Insert<DemoEntity>(entity); //更新 bool result = this.Update<DemoEntity>(entity); //根据主键返回实体 entity = this.GetById<DemoEntity>(1); //返回 行数 this.Count<DemoEntity>(new { ID = 1 }); //查询所有 IEnumerable<DemoEntity> list = this.GetAll<DemoEntity>(); IList<ISort> sort = new List<ISort>(); sort.Add(new Sort { PropertyName = "ID", Ascending = false }); //条件查询 list = this.GetList<DemoEntity>(new { ID = 1, Name = "123" }, sort); //orm 拼接条件 查询 IList<IPredicate> predList = new List<IPredicate>(); predList.Add(Predicates.Field<DemoEntity>(p => p.Name, Operator.Like, "不知道%")); predList.Add(Predicates.Field<DemoEntity>(p => p.ID, Operator.Eq, 1)); IPredicateGroup predGroup = Predicates.Group(GroupOperator.And, predList.ToArray()); list […]
View Details