UNPKG

vue-notifications

Version:
411 lines (205 loc) 12.8 kB
<!DOCTYPE HTML> <html lang="" > <head> <meta charset="UTF-8"> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>Advanced Setup · GitBook</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="description" content=""> <meta name="generator" content="GitBook 3.2.3"> <link rel="stylesheet" href="gitbook/style.css"> <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css"> <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css"> <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css"> <meta name="HandheldFriendly" content="true"/> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png"> <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon"> <link rel="next" href="how-it-works.html" /> <link rel="prev" href="what-you-shouldnt-do.html" /> </head> <body> <div class="book"> <div class="book-summary"> <div id="book-search-input" role="search"> <input type="text" placeholder="Type to search" /> </div> <nav role="navigation"> <ul class="summary"> <li class="chapter " data-level="1.1" data-path="./"> <a href="./"> Introduction and WTF is it? </a> </li> <li class="chapter " data-level="1.2" data-path="installation.html"> <a href="installation.html"> Installation </a> </li> <li class="chapter " data-level="1.3" data-path="getting-started.html"> <a href="getting-started.html"> Getting Started </a> </li> <li class="chapter " data-level="1.4" data-path="usage.html"> <a href="usage.html"> Usage </a> </li> <li class="chapter " data-level="1.5" data-path="what-you-shouldnt-do.html"> <a href="what-you-shouldnt-do.html"> What you shouldn't do </a> </li> <li class="chapter active" data-level="1.6" data-path="advanced-setup.html"> <a href="advanced-setup.html"> Advanced Setup </a> </li> <li class="chapter " data-level="1.7" data-path="how-it-works.html"> <a href="how-it-works.html"> How it works </a> </li> <li class="chapter " data-level="1.8" data-path="browsers-support.html"> <a href="browsers-support.html"> Browsers support </a> </li> <li class="chapter " data-level="1.9" data-path="vuejs-versions-support.html"> <a href="vuejs-versions-support.html"> Vuejs Versions Support </a> </li> <li class="chapter " data-level="1.10" > <a target="_blank" href="https://github.com/se-panfilov/vue-notifications/releases"> Release Notes </a> </li> <li class="divider"></li> <li> <a href="https://www.gitbook.com" target="blank" class="gitbook-link"> Published with GitBook </a> </li> </ul> </nav> </div> <div class="book-body"> <div class="body-inner"> <div class="book-header" role="navigation"> <!-- Title --> <h1> <i class="fa fa-circle-o-notch fa-spin"></i> <a href="." >Advanced Setup</a> </h1> </div> <div class="page-wrapper" tabindex="-1" role="main"> <div class="page-inner"> <div id="book-search-results"> <div class="search-noresults"> <section class="normal markdown-section"> <h1 id="advanced-setup">Advanced Setup</h1> <p>You could setup <code>vue-notificatio</code> a little bit more if you want</p> <h3 id="global-configuration">Global configuration</h3> <p><code>vue-notification</code> has some default values, such as <code>timeout</code> and <code>type</code>:</p> <pre><code class="lang-js">config: { type: TYPE.info, timeout: <span class="hljs-number">3000</span> } </code></pre> <p>You can override them via <code>config</code> object:</p> <pre><code>VueNotifications.config.timeout = 4000 VueNotifications.config.type = &apos;error&apos; </code></pre><p>You have to do it before <code>Vue.use(VueNotifications, options)</code> call.</p> <h3 id="your-own-property-name">Your own property name</h3> <p>If for some reasons you aren&apos;t happy with `notifications`, then you can set your own word for this case:</p> <pre><code>VueNotifications.propertyName = &apos;messages&apos; </code></pre><p>You have to do it before <code>Vue.use(VueNotifications, options)</code> call.</p> <p>And as a result you would be able to do:</p> <pre><code class="lang-js">/... messages: { errorMsg: { type: <span class="hljs-string">&apos;error&apos;</span>, title: <span class="hljs-string">&apos;Error title&apos;</span>, message: <span class="hljs-string">&apos;Some error msg&apos;</span> }, <span class="hljs-comment">//...</span> </code></pre> <p>Instead of</p> <pre><code class="lang-js"><span class="hljs-comment">//...</span> notifications: { errorMsg: { type: <span class="hljs-string">&apos;error&apos;</span>, title: <span class="hljs-string">&apos;Error title&apos;</span>, message: <span class="hljs-string">&apos;Some error msg&apos;</span> }, <span class="hljs-comment">//...</span> </code></pre> <h3 id="adding-custom-field">Adding custom field</h3> <p>Let&apos;s say we want to send our messages not only to UI lib (<a href="https://github.com/se-panfilov/mini-toastr" target="_blank">mini-toastr</a>?), but also to console.<br>In this case we can add some custom field to our notifications:</p> <pre><code class="lang-js">notifications: { showLoginError: { message: <span class="hljs-string">&apos;Failed to authenticate&apos;</span>, type: <span class="hljs-string">&apos;error&apos;</span>, consoleMessage: <span class="hljs-string">&apos;let it be in console&apos;</span> <span class="hljs-comment">// Our brand new field</span> } } </code></pre> <p>And here is our new mapping function from <a href="getting-started.html">Getting Started</a> section</p> <pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">toast</span> (<span class="hljs-params">{title, message, type, timeout, cb, consoleMessage}</span>) </span>{ <span class="hljs-keyword">if</span> (consoleMessage) <span class="hljs-built_in">console</span>[type](consoleMessage) <span class="hljs-comment">//Here we go!</span> <span class="hljs-keyword">return</span> miniToastr[type](message, title, timeout, cb) } </code></pre> <p>Don&apos;t forget to do:</p> <pre><code class="lang-js"><span class="hljs-keyword">const</span> options = { success: toast, error: toast, info: toast, warn: toast } Vue.use(VueNotifications, options) </code></pre> <p>After that</p> </section> </div> <div class="search-results"> <div class="has-results"> <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1> <ul class="search-results-list"></ul> </div> <div class="no-results"> <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1> </div> </div> </div> </div> </div> </div> <a href="what-you-shouldnt-do.html" class="navigation navigation-prev " aria-label="Previous page: What you shouldn't do"> <i class="fa fa-angle-left"></i> </a> <a href="how-it-works.html" class="navigation navigation-next " aria-label="Next page: How it works"> <i class="fa fa-angle-right"></i> </a> </div> <script> var gitbook = gitbook || []; gitbook.push(function() { gitbook.page.hasChanged({"page":{"title":"Advanced Setup","level":"1.6","depth":1,"next":{"title":"How it works","level":"1.7","depth":1,"path":"how-it-works.md","ref":"how-it-works.md","articles":[]},"previous":{"title":"What you shouldn't do","level":"1.5","depth":1,"path":"what-you-shouldnt-do.md","ref":"what-you-shouldnt-do.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"advanced-setup.md","mtime":"2019-05-08T14:09:27.855Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-08-01T12:24:20.020Z"},"basePath":".","book":{"language":""}}); }); </script> </div> <script src="gitbook/gitbook.js"></script> <script src="gitbook/theme.js"></script> <script src="gitbook/gitbook-plugin-search/search-engine.js"></script> <script src="gitbook/gitbook-plugin-search/search.js"></script> <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script> <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script> <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script> <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script> </body> </html>