首页 > 其他分享 >Web开发者福音!创建第一个Vite支持的Web应用(2/2)

Web开发者福音!创建第一个Vite支持的Web应用(2/2)

时间:2022-08-29 09:55:46浏览次数:72  
标签:Web .. url modules 开发者 dx css import Vite

Vite 是一个基于开发服务器的构建工具,它在启动应用程序之前组装 JavaScript 代码,同时Vite还有助于在进行更改时减少加载速度,并允许您几乎可以立即查看结果。

在这篇文章中,我们将解决前端 Web 开发人员的需求,并向您展示如何使用 Vite 库来显着提高 Javascript 客户端应用程序的启动/更新速度。

Vite将代码创建为ES模块——现代浏览器可以用来加载JavaScript的模块,在依赖较大的情况下,Vite 会预先捆绑这些模块,以减少浏览器对 Web 服务器的请求数量。在以下部分中,我们将向您展示如何将Vite添加到由DevExtreme提供支持的React Reporting应用程序中。

在上文中,我们已为大家介绍如何创建示例DevExtreme应用、配置应用程序来使用Vite和DevExpress Reports,具体步骤可点击查看回顾>>

接下来我们将继续介绍如何添加DevExpress Document Viewer和Report Designer组件等。

点击获取DevExpress v22.1正式版
添加DevExpress Document Viewer和Report Designer组件

添加Document Viewer的步骤

将 src/pages/document-viewer/document-viewer.tsx 文件内容替换为以下内容:

import React from 'react';
import ko from 'knockout';
import 'devexpress-reporting/dx-webdocumentviewer';
import './document-viewer.scss';

class ReportViewer extends React.Component {
constructor(props) {
super(props);
this.viewerRef = React.createRef();
this.reportUrl = ko.observable("Invoice");
this.requestOptions = {
host: "https://localhost:5001/",
invokeAction: "DXXRDV"
};
}
render() {
return (<div ref={this.viewerRef} data-bind="dxReportViewer: $data"></div>);
}
componentDidMount() {
ko.applyBindings({
reportUrl: this.reportUrl,
requestOptions: this.requestOptions
}, this.viewerRef.current);
}
componentWillUnmount() {
ko.cleanNode(this.viewerRef.current);
}
};

export default () => (
<React.Fragment>
<h2 className={'content-block'}>Document Viewer</h2>
<div className={'content-block'}>
<div className={'dx-card responsive-paddings'}>
<div style={{ width: "100%", height: "700px" }}>
<ReportViewer />
</div>
</div>
</div>
</React.Fragment>
);

以下属性指定报表名称:

this.reportUrl = ko.observable("Invoice");

主机指定服务器端应用地址:

host: https://localhost:5001/

最后在 src/pages/document-viewer/document-viewer.scss 页面添加如下内容:

@import url("../../../node_modules/jquery-ui/themes/base/all.css");
@import url("../../../node_modules/devextreme/dist/css/dx.material.orange.light.css");
@import url("../../../node_modules/@devexpress/analytics-core/dist/css/dx-analytics.common.css");
@import url("../../../node_modules/@devexpress/analytics-core/dist/css/dx-analytics.material.orange.light.css");
@import url("../../../node_modules/devexpress-reporting/dist/css/dx-webdocumentviewer.css");

添加DevExpress Report Designer的步骤

 src/pages/report-designer/report-designer.tsx 文件内容替换为以下内容:

import React from 'react';
import ko from 'knockout';
import 'devexpress-reporting/dx-reportdesigner';
import './report-designer.scss';

class ReportDesigner extends React.Component {
constructor(props) {
super(props);
this.designerRef = React.createRef();
this.reportUrl = ko.observable("Invoice");
this.requestOptions = {
host: "https://localhost:5001/",
getDesignerModelAction: "/DXXRD/GetDesignerModel"
};
}
render() {
return (<div ref={this.designerRef} data-bind="dxReportDesigner: $data"></div>);
}
componentDidMount() {
ko.applyBindings({
reportUrl: this.reportUrl,
requestOptions: this.requestOptions
}, this.designerRef.current);
}
componentWillUnmount() {
ko.cleanNode(this.designerRef.current);
}
};
export default () => (
<React.Fragment>
<h2 className={'content-block'}>Report Designer</h2>
<div className={'content-block'}>
<div className={'dx-card responsive-paddings'}>
<div style={{ width: "100%", height: "700px" }}>
<ReportDesigner />
</div>
</div>
</div>
</React.Fragment>
);

以下属性指定报表名称:

this.reportUrl = ko.observable("Invoice");

主机指定服务器端应用地址:

host: https://localhost:5001/

因此,将以下内容添加到 src/pages/report-designer/report-designer.scss 页面以完成此步骤:

@import url("../../../node_modules/jquery-ui/themes/base/all.css");
@import url("../../../node_modules/devextreme/dist/css/dx.material.orange.light.css");
@import url("../../../node_modules/@devexpress/analytics-core/dist/css/dx-analytics.common.css");
@import url("../../../node_modules/@devexpress/analytics-core/dist/css/dx-analytics.material.orange.light.css");
@import url("../../../node_modules/@devexpress/analytics-core/dist/css/dx-querybuilder.css");
@import url("../../../node_modules/devexpress-reporting/dist/css/dx-webdocumentviewer.css");
@import url("../../../node_modules/devexpress-reporting/dist/css/dx-reportdesigner.css");
运行报表后端应用程序

Web报表组件需要一个后端应用程序来存储和处理报告,运行后端应用程序以确定地址,并将该地址分别指定为 src/pages/document-viewer/document-viewer.tsx和src/pages/report-designer/report-designer中 ReportViewer和ReportDesigner组件的主机选项.tsx文件。

如果您刚刚创建了一个后端应用程序,可以从模板中创建一个TestReport,除了这个简单的报告,您还可以加载我们的发行版附带的报表。要加载报表,请在官方的WinForms Reporting演示中打开 Invoice 模块,切换到 Designer,然后将报表另存为REPX文件。在Visual Studio Report Designer中打开TestReport 报表,然后单击报表智能标记中的打开/导入以加载您保存的REPX文件。

运行客户端应用程序

确保后端应用程序正在运行,导航到devextreme-react-sample文件夹,然后执行以下命令:

npm install
npm run start

完成后,应用程序应如下所示:

 


DevExpress技术交流群6:600715373      欢迎一起进群讨论

更多DevExpress线上公开课、中文教程资讯请上中文网获取

标签:Web,..,url,modules,开发者,dx,css,import,Vite
From: https://www.cnblogs.com/AABBbaby/p/16634876.html

相关文章

  • CTFSHOW Web266
    highlight_file(__FILE__);include('flag.php');$cs=file_get_contents('php://input');classctfshow{public$username='xxxxxx';public$password='xxxxxx'......
  • 部署web服务器时虚拟路径的问题-什么是虚拟路径?有什么用?
    https://blog.csdn.net/sunjintaoxxx/article/details/119778776https://zhidao.baidu.com/question/11331085.html 当使用Dreamweaver将文件上传到远程服务器后,这些......
  • vite 构建移除 console
    vite3.x已经将esbuild作为默认构建选项,你可以通过如下配置在构建时移除代码中的console.log、debugger。//vite.config.tsimport{defineConfig}from'vite'e......
  • Vite配置如何优雅的code spliiting代码分割
    Vite如何配置分割代码什么是代码分割/codespliiting前端生态rollup和webpack都有的概念。如果把所有代码都打包到一起,可能最终的代码非常大。从而影响加载时间。而......
  • 【django学习-01】基于wsgi自制一个web框架
    什么是web框架框架,即farmework。特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统,简单地说,就是你用别人搭建好的舞台来做......
  • 在 React 中释放 Web 组件的力量
    在React中释放Web组件的力量Photoby法提赫on不飞溅假设您有一个项目,要求您在React应用程序中使用Web组件。你如何使用该组件的状态?如何访问它的方法和属......
  • web应用模式和api接口
    web应用模式:前后端不分离(客户端看到的内容和所有界面效果都是由服务端提供出来的)  2.前后端分离(把前端的界面效果(html,css,js分离到另一个服务端,python服务......
  • Vue3+vite+js 配置别名@报错
    Vue3+vite+js配置别名@报错vue3项目中配置vite.config.js时使用path模块报错,一直警告找不大到path模块原因:path模块是node.js内置的功能,但是node.js本身并不支持ts解决......
  • FUXA——基于Web的过程可视化软件
    资源GitHub地址:https://github.com/frangoteam/FUXADEMO地址:https://frangoteam.github.io/概述FUXA是基于Web的,过程(SCADA、HMI、看板等)可视化软件。可创建现代的......
  • 使用IDEA如何配置Web项目的Tomcat
    1.打开项目,点击右上角,选择编辑项目配置(“EditConfigurations...”)。 2.弹出窗口,点击“+”,选择TomacatServer服务器。 3.配置jre的Tomcat环境变量。 4.将项......