A common use case for Quasar applications is to run code before the root Vue app instance is instantiated, like injecting and initializing your own dependencies (examples: Vue components, libraries…) or simply configuring some startup code of your app.

在quasar 框架中boot 文件通常在root Vue被实例化之前运行,比如注册和初始化自己的依赖

(例如vue组件,库等)或者是app启动程序的一些简单配置。

Since you won’t be having access to any /main.js

file (so that Quasar CLI can seamlessly initialize and build same codebase for SPA/PWA/SSR/Cordova/Electron) Quasar provides an elegant solution to that problem by allowing users to define so-called boot files.

由于没有main.js文件(因此quasar CLI才能为SPA/PWA/SSR/Cordova/Electron无缝隙初始化与构建时使用相同的代码库)quasar允许用户自定义boot文件。

In earlier Quasar versions, to run code before the root Vue instance was instantiated, you could alter the /src/main.js

file and add any code you needed to execute.

在早期的版本中,root Vue实例被实例化之前,可以通过修改src下的main.js文件,添加需要执行的代码。

There is a major problem with this approach: with a growing project, your main.js

file was very likely to get cluttered and challenging to maintain, which breaks with Quasar’s concept of encouraging developers to write maintainable and elegant cross-platform applications.

这样就产生了一个问题:随着项目的发展,main.js文件将会变的臃肿且难以维护.将破坏quasar

倡导开发者编写优雅且可维护的 跨平台程序的理念。

With boot files, it is possible to split each of your dependencies into self-contained, easy to maintain files. It is also trivial to disable any of the boot files or even contextually determine which of the boot files get into the build through quasar.conf.js

configuration.

通过boot文件,可以拆分为每一个独立,易维护的boot文件,这些boot文件可以在quasar.conf.js配置文件中设置禁用和启用。

所以我们通过创建一个boot启动文件来注入全局的filter,步骤如下:

一、使用Quasar CLI生成一个boot文件名:

quasar new boot

这个name自己随意起,CLi会在/src/boot/生成这个js文件

二、在生成的这个文件中编写需要的filter内容

三、在quasar.conf.js中把这个文件名添加到启动配置中

最后可以在vue页面中直接使用



参考资料:

https://github.com/cuatromedios/quasar-app-extension-filters/blob/master/src/boot/register-filters.js

在quasar 注册全局filter的更多相关文章

  1. vue 中全局filter过滤器的配置及使用

    在项目中使用到的经常用到过滤器,比如时间,数据截取等过滤器,如果在每个.vue中都可以复制同一个过滤器,这可以达到目的,但是遇到方法有bug时就需要诸葛修改进入不同的页面修改,这样既费时又费力,优先可 ...

  2. Dubbo的全局Filter配置

    前言: 之前也写过dubbo的filter的文章, 后来和同事也有过交流, 才发生自己对dubbo的filter的机制, 还是存在一些误解, 尤其是自定义filter的定位, 不是那么清晰. 本文主要 ...

  3. vue 注册全局组件

    注册全局组件有啥好处呢? 提高代码的复用性:哪里需要写哪里,贼方便,就写一个标签:减少代码量:可以再配合slot一起使用,咦~~,舒服 为了让整个项目的可读性,我创建一个文件统一存放全局组件 1.创建 ...

  4. vue中全局filter和局部filter怎么用?

    需求: 将价值上加上元单位符号(全局filter) <template> <div> 衣服价格:{{productPrice|formatTime}} </div> ...

  5. vue 中注册全局组件

    1  全局注册组件 建一个 js 文件, 注册全局组件, 并且暴露出去 然后再在 main.js  中引入       在页面就可以直接使用了    2 全局注册过滤器 建立文件, 包含所有过滤器方法 ...

  6. vue 自动注册全局组件

    vue 自动注册全局组件 vue 注册全局组件的方式 const plugins = { install(Vue) { const requireComponent = require.context ...

  7. Django_注册全局消息

    需求: 对于登录用户,无论他在哪个页面,我都需要给他全局发送一个消息提示,Django中request就是一个全局变量 那,如何做? 在models 中urser表,继承user的表类中写上一个函数, ...

  8. SpringBoot注册Servlet/Filter/Listener

    由于SpringBoot默认是以jar包的方式启动嵌入式的Servlet容器来启动SpringBoot的web应用,那么没有web.xml文件,如何配置我们的三大Web基础组件呢? 通过使用XXXRe ...

  9. Vue自动化注册全局组件脚本

    今天有一个idea,vue一些组件,可能会全局都用到,我觉得在main.js写 Vue.component(name, instance) 然后很命令式,写着也不好看,想着能够有一个函数可以指定加载比 ...

随机推荐

  1. zookeeper 异常 :stat is not executed because it is not in the whitelist. Connection closed b

    1 .问题 1.启动 zookeeper 后 用指令:  telnet 127.0.0.1 2181 连接 提示输入指令 :stat 后报错,然后关闭连接 2.问题解决: 修改启动指令 zkServe ...

  2. 【Java 多线程】Java线程池类ThreadPoolExecutor、ScheduledThreadPoolExecutor及Executors工厂类

    Java中的线程池类有两个,分别是:ThreadPoolExecutor和ScheduledThreadPoolExecutor,这两个类都继承自ExecutorService.利用这两个类,可以创建 ...

  3. 二进制转换为ip地址

    #include <stdio.h> #include<math.h> int power(int b)//定义幂函数 { int i = 2, j = 1; if (b == ...

  4. HDC2021技术分论坛:进程崩溃/应用卡死,故障频频怎么办?

    ​作者:jiwenqiang,DFX技术专家 提到开发一个产品,我们通常首先想到的是要实现什么样的功能,但是除了功能之外,非功能属性也会很大程度上影响一个产品的体验效果,比如不定时出现的应用卡死.崩溃 ...

  5. 3、Linux的Redis安装

    Linux下安装redis 1.Redis下载 [Redis官网下载地址](https://redis.io/download)    进入官网进行下载 wget https://download.r ...

  6. Linux内核启动流程(简介)

    1. vmlinux.lds 首先分析 Linux 内核的连接脚本文件 arch/arm/kernel/vmlinux.lds,通过链接脚本可以找到 Linux 内核的第一行程序是从哪里执行的: 第 ...

  7. centos源码部署lua-5.3

    目录 一.介绍 二.部署 三.测试 一.介绍 Luat语言是在1993年由巴西一个大学研究小组发明,其设计目标是作为嵌入式程序移植到其他应用程序,它是由C语言实现的,虽然简单小巧但是功能强大. 二.部 ...

  8. [BUUCTF]PWN——ciscn_2019_es_2

    ciscn_2019_es_2 附件 步骤: 例行检查,32位程序,开启了nx保护 32位ida载入,shif+f12查看程序里的字符串,这边的"echo flag" 是个迷惑性的 ...

  9. Oracle 函数高级查询

    目录 oracle高级查询 Oracle SQL获取每个分组中日期最新的一条数据 求平均值(为0的参数不均摊) 字符串清除前面的0 判断字符串串是否包含某个字符串 switch 判断 oracle不足 ...

  10. 在【自定义列】中使用M函数(Power Query 之 M 语言)

    数据源: "品名"一列 目标: 提取品名中的首字符,生成新列:"品名简称" 解决方案: 在[自定义列]中使用M函数Text.Start 步骤: 打开[自定义列] ...