├── .babelrc ├── src ├── build.js └── VueHelmet.js ├── .editorconfig ├── .eslintrc.js ├── .gitignore ├── webpack.config.js ├── webpack.common.js ├── LICENSE ├── package.json ├── README.md └── dist ├── vue-helmet.common.js ├── vue-helmet.min.js └── vue-helmet.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"], 3 | "plugins": ["transform-runtime"] 4 | } -------------------------------------------------------------------------------- /src/build.js: -------------------------------------------------------------------------------- 1 | import VueHelmetComponent from './VueHelmet' 2 | 3 | export function install(Vue) { 4 | Vue.component('vue-helmet', VueHelmetComponent) 5 | } 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style 4 | extends: 'standard', 5 | // required to lint *.vue files 6 | env: { 7 | 'browser': true, 8 | }, 9 | plugins: [ 10 | 'html' 11 | ], 12 | // add your custom rules here 13 | 'rules': { 14 | // allow paren-less arrow functions 15 | 'arrow-parens': 0, 16 | // allow debugger during development 17 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, 18 | 'comma-dangle': 0, 19 | 'no-unused-vars': 1, 20 | 'space-before-function-paren': 0, 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var webpack = require('webpack'); 2 | var version = require("./package.json").version; 3 | var banner = 4 | "/**\n" + 5 | " * vue-helmet v" + version + "\n" + 6 | " * https://github.com/miaolz123/vue-helmet\n" + 7 | " * MIT License\n" + 8 | " */\n"; 9 | 10 | module.exports = { 11 | entry: './src/build.js', 12 | output: { 13 | path: './dist', 14 | filename: 'vue-helmet.js', 15 | library: 'VueHelmet', 16 | libraryTarget: 'umd' 17 | }, 18 | plugins: [ 19 | new webpack.BannerPlugin(banner, { raw: true }) 20 | ], 21 | module: { 22 | loaders: [{ 23 | test: /\.vue$/, 24 | loader: 'vue' 25 | }, { 26 | test: /\.css$/, 27 | loader: "style!css" 28 | }, { 29 | test: /\.js$/, 30 | loader: 'babel', 31 | exclude: /node_modules/ 32 | }, { 33 | test: /\.json$/, 34 | loader: 'json-loader' 35 | }] 36 | }, 37 | } 38 | -------------------------------------------------------------------------------- /webpack.common.js: -------------------------------------------------------------------------------- 1 | var webpack = require("webpack"); 2 | var version = require("./package.json").version; 3 | var banner = 4 | "/**\n" + 5 | " * vue-helmet v" + version + "\n" + 6 | " * https://github.com/miaolz123/vue-helmet\n" + 7 | " * MIT License\n" + 8 | " */\n"; 9 | 10 | module.exports = { 11 | entry: "./src/VueHelmet.js", 12 | target: "node", 13 | output: { 14 | path: "./dist", 15 | filename: "vue-helmet.common.js", 16 | library: "VueHelmet", 17 | libraryTarget: "umd" 18 | }, 19 | externals: /^[^.]/, 20 | plugins: [ 21 | new webpack.BannerPlugin(banner, { raw: true }) 22 | ], 23 | module: { 24 | loaders: [{ 25 | test: /\.vue$/, 26 | loader: "vue" 27 | }, { 28 | test: /\.js$/, 29 | loader: "babel", 30 | exclude: /node_modules/ 31 | }, { 32 | test: /\.css$/, 33 | loader: "style!css" 34 | }, { 35 | test: /\.json$/, 36 | loader: "json-loader" 37 | }] 38 | }, 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 miaolz123 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-helmet", 3 | "version": "1.1.5", 4 | "description": "A HTML head manager for Vue", 5 | "main": "dist/vue-helmet.common.js", 6 | "files": [ 7 | "dist/vue-helmet.js", 8 | "dist/vue-helmet.min.js", 9 | "dist/vue-helmet.common.js", 10 | "src" 11 | ], 12 | "scripts": { 13 | "start": "webpack --config webpack.config.js", 14 | "min": "uglifyjs ./dist/vue-helmet.js -m -c --noerr -o ./dist/vue-helmet.min.js", 15 | "build": "webpack --config webpack.common.js", 16 | "test": "echo true" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/miaolz123/vue-helmet.git" 21 | }, 22 | "keywords": [ 23 | "vue", 24 | "helmet", 25 | "vue-helmet" 26 | ], 27 | "author": "miaolz123", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/miaolz123/vue-helmet/issues" 31 | }, 32 | "homepage": "https://github.com/miaolz123/vue-helmet#readme", 33 | "devDependencies": { 34 | "babel-core": "^6.8.0", 35 | "babel-loader": "^6.2.4", 36 | "babel-plugin-transform-es2015-parameters": "^6.8.0", 37 | "babel-plugin-transform-runtime": "^6.8.0", 38 | "babel-preset-es2015": "^6.6.0", 39 | "babel-runtime": "^6.6.1", 40 | "webpack": "^1.13.0" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-helmet 2 | 3 | [![npm](https://img.shields.io/npm/v/vue-helmet.svg?style=flat)](https://www.npmjs.com/package/vue-helmet) 4 | [![npm](https://img.shields.io/npm/l/vue-helmet.svg?style=flat)](https://www.npmjs.com/package/vue-helmet) 5 | [![npm](https://img.shields.io/npm/dt/vue-helmet.svg?style=flat)](https://www.npmjs.com/package/vue-helmet) 6 | 7 | Like [react-helmet](https://github.com/nfl/react-helmet), a HTML head manager for Vue, edit the page title easily! 8 | 9 | # Instllation 10 | 11 | ### Browser globals 12 | 13 | > The **dist** folder contains `vue-helmet.js` and `vue-helmet.min.js` with the component exported in the `window.VueHelmet` object. 14 | 15 | ```html 16 | 17 | 18 | 24 | ``` 25 | 26 | ### NPM 27 | 28 | ```shell 29 | $ npm install --save vue-helmet 30 | ``` 31 | 32 | ## CommonJS 33 | 34 | ```js 35 | var VueHelmet = require('vue-helmet'); 36 | 37 | new Vue({ 38 | components: { 39 | 'vue-helmet': VueHelmet 40 | } 41 | }) 42 | ``` 43 | 44 | ## ES6 45 | 46 | ```js 47 | import VueHelmet from 'vue-helmet' 48 | 49 | new Vue({ 50 | components: { 51 | VueHelmet 52 | } 53 | }) 54 | ``` 55 | 56 | # Example 57 | 58 | - vue-router & vue-helmet Example : [Code](//github.com/miaolz123/vue-helmet/tree/gh-pages) | [Demo](//miaolz123.github.io/vue-helmet/) 59 | - ... 60 | 61 | # Props 62 | 63 | | Prop | Type | Example | 64 | | ---- | ---- | ------- | 65 | | html-attributes | Object | `:html-attributes="{'lang': 'zh-CN'}"` | 66 | | title | String | `title="New Title Here"` | 67 | | base | Object | `:base="{'target': '_blank', 'href': 'http://a.d.c'}"` | 68 | | meta | Object | `:meta="{'description': 'New Description Here.'}"` | 69 | | links | Array | `:links="[{'rel': 'canonical', 'href': 'http://a.b.c'}]"` | 70 | | scripts | Array | `:scripts="[{'type': 'text/javascript', 'src': 'http://abc.xyz/filename.js'}]"` | 71 | 72 | # Contributors 73 | 74 | - [miaolz123](//github.com/miaolz123) 75 | - [MouCai](//github.com/MouCai) 76 | 77 | # License 78 | 79 | Copyright (c) 2016 [miaolz123](//github.com/miaolz123) by [MIT](//opensource.org/licenses/MIT) -------------------------------------------------------------------------------- /src/VueHelmet.js: -------------------------------------------------------------------------------- 1 | const isArrayLike = (obj) => { 2 | const jtype = (obj) => { 3 | let class2type = {} 4 | let toString = class2type.toString 5 | if (obj == null) { 6 | return obj + '' 7 | } 8 | return typeof obj === 'object' || typeof obj === 'function' 9 | ? class2type[toString.call(obj)] || 'object' : typeof obj 10 | } 11 | const isWindow = (obj) => { 12 | return obj != null && obj === obj.window 13 | } 14 | let length = !!obj && 'length' in obj && obj.length 15 | let type = jtype(obj) 16 | if (type === 'function' || isWindow(obj)) { 17 | return false 18 | } 19 | return type === 'array' || length === 0 || 20 | typeof length === 'number' && length > 0 && (length - 1) in obj 21 | } 22 | 23 | const range = (obj, callback) => { 24 | let length = 0 25 | let i = 0 26 | if (isArrayLike(obj)) { 27 | length = obj.length 28 | for (; i < length; i++) { 29 | if (callback.call(obj[i], i, obj[i]) === false) { 30 | break 31 | } 32 | } 33 | } else { 34 | for (i in obj) { 35 | if (callback.call(obj[i], i, obj[i]) === false) { 36 | break 37 | } 38 | } 39 | } 40 | return obj 41 | } 42 | 43 | const updateHtmlAttributes = (attributes) => { 44 | const htmlTags = document.getElementsByTagName('html') 45 | if (htmlTags.length > 0) { 46 | range(attributes, (k, v) => { 47 | htmlTags[0].setAttribute(k, v) 48 | }) 49 | } 50 | } 51 | 52 | const updateBase = (attributes) => { 53 | const headElement = document.head || document.querySelector('head') 54 | const oldBases = headElement.getElementsByTagName('base') 55 | const newBase = document.createElement('base') 56 | range(oldBases, () => { 57 | headElement.removeChild(oldBases[0]) 58 | }) 59 | range(attributes, (k, v) => { 60 | newBase.setAttribute(k, v) 61 | }) 62 | headElement.appendChild(newBase) 63 | } 64 | 65 | const updateMeta = (attributes) => { 66 | const headElement = document.head || document.querySelector('head') 67 | const oldMetas = headElement.getElementsByTagName('meta') 68 | const attributeKeys = Object.keys(attributes) 69 | let i = 0 70 | range(oldMetas, () => { 71 | if (attributeKeys.indexOf(oldMetas[i].name) > -1) { 72 | headElement.removeChild(oldMetas[i]) 73 | } else i++ 74 | }) 75 | range(attributes, (k, v) => { 76 | const newElement = document.createElement('meta') 77 | newElement.setAttribute('name', k) 78 | newElement.setAttribute('content', v) 79 | headElement.appendChild(newElement) 80 | }) 81 | } 82 | 83 | const updateLink = (links) => { 84 | const headElement = document.head || document.querySelector('head') 85 | const oldLinks = headElement.getElementsByTagName('link') 86 | range(links, (i, link) => { 87 | const newElement = document.createElement('link') 88 | range(link, (k, v) => { 89 | newElement.setAttribute(k, v) 90 | }) 91 | range(oldLinks, (index) => { 92 | if (oldLinks[index].isEqualNode(newElement)) { 93 | headElement.removeChild(oldLinks[index]) 94 | } 95 | }) 96 | headElement.appendChild(newElement) 97 | }) 98 | } 99 | 100 | const updateScript = (scripts) => { 101 | const headElement = document.head || document.querySelector('head') 102 | const oldScripts = headElement.getElementsByTagName('script') 103 | range(scripts, (i, script) => { 104 | const newElement = document.createElement('script') 105 | range(script, (k, v) => { 106 | newElement.setAttribute(k, v) 107 | }) 108 | range(oldScripts, (index) => { 109 | if (oldScripts[index].isEqualNode(newElement)) { 110 | headElement.removeChild(oldScripts[index]) 111 | } 112 | }) 113 | headElement.appendChild(newElement) 114 | }) 115 | } 116 | 117 | const flush = () => { 118 | const htmlTags = document.getElementsByTagName('html') 119 | if (htmlTags.length > 0) { 120 | const bodies = htmlTags[0].getElementsByTagName('body') 121 | range(bodies, (i, body) => { 122 | if (i + 1 < bodies.length && body.childElementCount === 0) { 123 | htmlTags[0].removeChild(body) 124 | } 125 | }) 126 | } 127 | } 128 | 129 | const doRender = (callback) => { 130 | callback.call() 131 | const ua = navigator.userAgent.toLowerCase() 132 | if (ua.indexOf('iphone') > -1 && ua.indexOf('micromessenger') > -1) { 133 | setTimeout(() => { 134 | callback.call() 135 | const iframe = document.createElement('iframe') 136 | iframe.style.visibility = 'hidden' 137 | iframe.style.width = '1px' 138 | iframe.style.height = '1px' 139 | iframe.src = '/favicon.ico' 140 | iframe.onload = () => { 141 | setTimeout(() => { 142 | document.body.removeChild(iframe) 143 | }, 0) 144 | } 145 | document.body.appendChild(iframe) 146 | }, 0) 147 | } 148 | } 149 | 150 | export default { 151 | props: { 152 | htmlAttributes: { 153 | type: Object, 154 | }, 155 | title: { 156 | type: String, 157 | }, 158 | base: { 159 | type: Object, 160 | }, 161 | meta: { 162 | type: Object, 163 | }, 164 | links: { 165 | type: Array, 166 | }, 167 | scripts: { 168 | type: Array, 169 | }, 170 | }, 171 | data: () => ({ 172 | head: document.head.outerHTML, 173 | }), 174 | ready() { 175 | doRender(() => { 176 | if (this.htmlAttributes) updateHtmlAttributes(this.htmlAttributes) 177 | if (this.title) document.title = this.title 178 | if (this.base) updateBase(this.base) 179 | if (this.meta) updateMeta(this.meta) 180 | if (this.links) updateLink(this.links) 181 | if (this.scripts) updateScript(this.scripts) 182 | flush() 183 | }) 184 | }, 185 | beforeDestroy() { 186 | doRender(() => { 187 | document.head.outerHTML = this.head 188 | flush() 189 | }) 190 | }, 191 | } 192 | -------------------------------------------------------------------------------- /dist/vue-helmet.common.js: -------------------------------------------------------------------------------- 1 | /** 2 | * vue-helmet v1.1.5 3 | * https://github.com/miaolz123/vue-helmet 4 | * MIT License 5 | */ 6 | 7 | (function webpackUniversalModuleDefinition(root, factory) { 8 | if(typeof exports === 'object' && typeof module === 'object') 9 | module.exports = factory(require("babel-runtime/core-js/object/keys"), require("babel-runtime/helpers/typeof")); 10 | else if(typeof define === 'function' && define.amd) 11 | define(["babel-runtime/core-js/object/keys", "babel-runtime/helpers/typeof"], factory); 12 | else if(typeof exports === 'object') 13 | exports["VueHelmet"] = factory(require("babel-runtime/core-js/object/keys"), require("babel-runtime/helpers/typeof")); 14 | else 15 | root["VueHelmet"] = factory(root["babel-runtime/core-js/object/keys"], root["babel-runtime/helpers/typeof"]); 16 | })(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_2__) { 17 | return /******/ (function(modules) { // webpackBootstrap 18 | /******/ // The module cache 19 | /******/ var installedModules = {}; 20 | 21 | /******/ // The require function 22 | /******/ function __webpack_require__(moduleId) { 23 | 24 | /******/ // Check if module is in cache 25 | /******/ if(installedModules[moduleId]) 26 | /******/ return installedModules[moduleId].exports; 27 | 28 | /******/ // Create a new module (and put it into the cache) 29 | /******/ var module = installedModules[moduleId] = { 30 | /******/ exports: {}, 31 | /******/ id: moduleId, 32 | /******/ loaded: false 33 | /******/ }; 34 | 35 | /******/ // Execute the module function 36 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 37 | 38 | /******/ // Flag the module as loaded 39 | /******/ module.loaded = true; 40 | 41 | /******/ // Return the exports of the module 42 | /******/ return module.exports; 43 | /******/ } 44 | 45 | 46 | /******/ // expose the modules object (__webpack_modules__) 47 | /******/ __webpack_require__.m = modules; 48 | 49 | /******/ // expose the module cache 50 | /******/ __webpack_require__.c = installedModules; 51 | 52 | /******/ // __webpack_public_path__ 53 | /******/ __webpack_require__.p = ""; 54 | 55 | /******/ // Load entry module and return exports 56 | /******/ return __webpack_require__(0); 57 | /******/ }) 58 | /************************************************************************/ 59 | /******/ ([ 60 | /* 0 */ 61 | /***/ function(module, exports, __webpack_require__) { 62 | 63 | 'use strict'; 64 | 65 | Object.defineProperty(exports, "__esModule", { 66 | value: true 67 | }); 68 | 69 | var _keys = __webpack_require__(1); 70 | 71 | var _keys2 = _interopRequireDefault(_keys); 72 | 73 | var _typeof2 = __webpack_require__(2); 74 | 75 | var _typeof3 = _interopRequireDefault(_typeof2); 76 | 77 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 78 | 79 | var isArrayLike = function isArrayLike(obj) { 80 | var jtype = function jtype(obj) { 81 | var class2type = {}; 82 | var toString = class2type.toString; 83 | if (obj == null) { 84 | return obj + ''; 85 | } 86 | return (typeof obj === 'undefined' ? 'undefined' : (0, _typeof3.default)(obj)) === 'object' || typeof obj === 'function' ? class2type[toString.call(obj)] || 'object' : typeof obj === 'undefined' ? 'undefined' : (0, _typeof3.default)(obj); 87 | }; 88 | var isWindow = function isWindow(obj) { 89 | return obj != null && obj === obj.window; 90 | }; 91 | var length = !!obj && 'length' in obj && obj.length; 92 | var type = jtype(obj); 93 | if (type === 'function' || isWindow(obj)) { 94 | return false; 95 | } 96 | return type === 'array' || length === 0 || typeof length === 'number' && length > 0 && length - 1 in obj; 97 | }; 98 | 99 | var range = function range(obj, callback) { 100 | var length = 0; 101 | var i = 0; 102 | if (isArrayLike(obj)) { 103 | length = obj.length; 104 | for (; i < length; i++) { 105 | if (callback.call(obj[i], i, obj[i]) === false) { 106 | break; 107 | } 108 | } 109 | } else { 110 | for (i in obj) { 111 | if (callback.call(obj[i], i, obj[i]) === false) { 112 | break; 113 | } 114 | } 115 | } 116 | return obj; 117 | }; 118 | 119 | var updateHtmlAttributes = function updateHtmlAttributes(attributes) { 120 | var htmlTags = document.getElementsByTagName('html'); 121 | if (htmlTags.length > 0) { 122 | range(attributes, function (k, v) { 123 | htmlTags[0].setAttribute(k, v); 124 | }); 125 | } 126 | }; 127 | 128 | var updateBase = function updateBase(attributes) { 129 | var headElement = document.head || document.querySelector('head'); 130 | var oldBases = headElement.getElementsByTagName('base'); 131 | var newBase = document.createElement('base'); 132 | range(oldBases, function () { 133 | headElement.removeChild(oldBases[0]); 134 | }); 135 | range(attributes, function (k, v) { 136 | newBase.setAttribute(k, v); 137 | }); 138 | headElement.appendChild(newBase); 139 | }; 140 | 141 | var updateMeta = function updateMeta(attributes) { 142 | var headElement = document.head || document.querySelector('head'); 143 | var oldMetas = headElement.getElementsByTagName('meta'); 144 | var attributeKeys = (0, _keys2.default)(attributes); 145 | var i = 0; 146 | range(oldMetas, function () { 147 | if (attributeKeys.indexOf(oldMetas[i].name) > -1) { 148 | headElement.removeChild(oldMetas[i]); 149 | } else i++; 150 | }); 151 | range(attributes, function (k, v) { 152 | var newElement = document.createElement('meta'); 153 | newElement.setAttribute('name', k); 154 | newElement.setAttribute('content', v); 155 | headElement.appendChild(newElement); 156 | }); 157 | }; 158 | 159 | var updateLink = function updateLink(links) { 160 | var headElement = document.head || document.querySelector('head'); 161 | var oldLinks = headElement.getElementsByTagName('link'); 162 | range(links, function (i, link) { 163 | var newElement = document.createElement('link'); 164 | range(link, function (k, v) { 165 | newElement.setAttribute(k, v); 166 | }); 167 | range(oldLinks, function (index) { 168 | if (oldLinks[index].isEqualNode(newElement)) { 169 | headElement.removeChild(oldLinks[index]); 170 | } 171 | }); 172 | headElement.appendChild(newElement); 173 | }); 174 | }; 175 | 176 | var updateScript = function updateScript(scripts) { 177 | var headElement = document.head || document.querySelector('head'); 178 | var oldScripts = headElement.getElementsByTagName('script'); 179 | range(scripts, function (i, script) { 180 | var newElement = document.createElement('script'); 181 | range(script, function (k, v) { 182 | newElement.setAttribute(k, v); 183 | }); 184 | range(oldScripts, function (index) { 185 | if (oldScripts[index].isEqualNode(newElement)) { 186 | headElement.removeChild(oldScripts[index]); 187 | } 188 | }); 189 | headElement.appendChild(newElement); 190 | }); 191 | }; 192 | 193 | var flush = function flush() { 194 | var htmlTags = document.getElementsByTagName('html'); 195 | if (htmlTags.length > 0) { 196 | (function () { 197 | var bodies = htmlTags[0].getElementsByTagName('body'); 198 | range(bodies, function (i, body) { 199 | if (i + 1 < bodies.length && body.childElementCount === 0) { 200 | htmlTags[0].removeChild(body); 201 | } 202 | }); 203 | })(); 204 | } 205 | }; 206 | 207 | var doRender = function doRender(callback) { 208 | callback.call(); 209 | var ua = navigator.userAgent.toLowerCase(); 210 | if (ua.indexOf('iphone') > -1 && ua.indexOf('micromessenger') > -1) { 211 | setTimeout(function () { 212 | callback.call(); 213 | var iframe = document.createElement('iframe'); 214 | iframe.style.visibility = 'hidden'; 215 | iframe.style.width = '1px'; 216 | iframe.style.height = '1px'; 217 | iframe.src = '/favicon.ico'; 218 | iframe.onload = function () { 219 | setTimeout(function () { 220 | document.body.removeChild(iframe); 221 | }, 0); 222 | }; 223 | document.body.appendChild(iframe); 224 | }, 0); 225 | } 226 | }; 227 | 228 | exports.default = { 229 | props: { 230 | htmlAttributes: { 231 | type: Object 232 | }, 233 | title: { 234 | type: String 235 | }, 236 | base: { 237 | type: Object 238 | }, 239 | meta: { 240 | type: Object 241 | }, 242 | links: { 243 | type: Array 244 | }, 245 | scripts: { 246 | type: Array 247 | } 248 | }, 249 | data: function data() { 250 | return { 251 | head: document.head.outerHTML 252 | }; 253 | }, 254 | ready: function ready() { 255 | var _this = this; 256 | 257 | doRender(function () { 258 | if (_this.htmlAttributes) updateHtmlAttributes(_this.htmlAttributes); 259 | if (_this.title) document.title = _this.title; 260 | if (_this.base) updateBase(_this.base); 261 | if (_this.meta) updateMeta(_this.meta); 262 | if (_this.links) updateLink(_this.links); 263 | if (_this.scripts) updateScript(_this.scripts); 264 | flush(); 265 | }); 266 | }, 267 | beforeDestroy: function beforeDestroy() { 268 | var _this2 = this; 269 | 270 | doRender(function () { 271 | document.head.outerHTML = _this2.head; 272 | flush(); 273 | }); 274 | } 275 | }; 276 | 277 | /***/ }, 278 | /* 1 */ 279 | /***/ function(module, exports) { 280 | 281 | module.exports = __WEBPACK_EXTERNAL_MODULE_1__; 282 | 283 | /***/ }, 284 | /* 2 */ 285 | /***/ function(module, exports) { 286 | 287 | module.exports = __WEBPACK_EXTERNAL_MODULE_2__; 288 | 289 | /***/ } 290 | /******/ ]) 291 | }); 292 | ; -------------------------------------------------------------------------------- /dist/vue-helmet.min.js: -------------------------------------------------------------------------------- 1 | !function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.VueHelmet=n():t.VueHelmet=n()}(this,function(){return function(t){function n(r){if(e[r])return e[r].exports;var o=e[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var e={};return n.m=t,n.c=e,n.p="",n(0)}([function(t,n,e){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t){t.component("vue-helmet",u["default"])}Object.defineProperty(n,"__esModule",{value:!0}),n.install=o;var i=e(1),u=r(i)},function(t,n,e){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(n,"__esModule",{value:!0});var o=e(2),i=r(o),u=e(37),c=r(u),f=function(t){var n=function(t){var n={},e=n.toString;return null==t?t+"":"object"===("undefined"==typeof t?"undefined":(0,c["default"])(t))||"function"==typeof t?n[e.call(t)]||"object":"undefined"==typeof t?"undefined":(0,c["default"])(t)},e=function(t){return null!=t&&t===t.window},r=!!t&&"length"in t&&t.length,o=n(t);return"function"!==o&&!e(t)&&("array"===o||0===r||"number"==typeof r&&r>0&&r-1 in t)},a=function(t,n){var e=0,r=0;if(f(t))for(e=t.length;r0&&a(t,function(t,e){n[0].setAttribute(t,e)})},l=function(t){var n=document.head||document.querySelector("head"),e=n.getElementsByTagName("base"),r=document.createElement("base");a(e,function(){n.removeChild(e[0])}),a(t,function(t,n){r.setAttribute(t,n)}),n.appendChild(r)},p=function(t){var n=document.head||document.querySelector("head"),e=n.getElementsByTagName("meta"),r=(0,i["default"])(t),o=0;a(e,function(){r.indexOf(e[o].name)>-1?n.removeChild(e[o]):o++}),a(t,function(t,e){var r=document.createElement("meta");r.setAttribute("name",t),r.setAttribute("content",e),n.appendChild(r)})},d=function(t){var n=document.head||document.querySelector("head"),e=n.getElementsByTagName("link");a(t,function(t,r){var o=document.createElement("link");a(r,function(t,n){o.setAttribute(t,n)}),a(e,function(t){e[t].isEqualNode(o)&&n.removeChild(e[t])}),n.appendChild(o)})},y=function(t){var n=document.head||document.querySelector("head"),e=n.getElementsByTagName("script");a(t,function(t,r){var o=document.createElement("script");a(r,function(t,n){o.setAttribute(t,n)}),a(e,function(t){e[t].isEqualNode(o)&&n.removeChild(e[t])}),n.appendChild(o)})},v=function(){var t=document.getElementsByTagName("html");t.length>0&&!function(){var n=t[0].getElementsByTagName("body");a(n,function(e,r){e+1-1&&n.indexOf("micromessenger")>-1&&setTimeout(function(){t.call();var n=document.createElement("iframe");n.style.visibility="hidden",n.style.width="1px",n.style.height="1px",n.src="/favicon.ico",n.onload=function(){setTimeout(function(){document.body.removeChild(n)},0)},document.body.appendChild(n)},0)};n["default"]={props:{htmlAttributes:{type:Object},title:{type:String},base:{type:Object},meta:{type:Object},links:{type:Array},scripts:{type:Array}},data:function(){return{head:document.head.outerHTML}},ready:function(){var t=this;h(function(){t.htmlAttributes&&s(t.htmlAttributes),t.title&&(document.title=t.title),t.base&&l(t.base),t.meta&&p(t.meta),t.links&&d(t.links),t.scripts&&y(t.scripts),v()})},beforeDestroy:function(){var t=this;h(function(){document.head.outerHTML=t.head,v()})}}},function(t,n,e){t.exports={"default":e(3),__esModule:!0}},function(t,n,e){e(4),t.exports=e(24).Object.keys},function(t,n,e){var r=e(5),o=e(7);e(22)("keys",function(){return function(t){return o(r(t))}})},function(t,n,e){var r=e(6);t.exports=function(t){return Object(r(t))}},function(t,n){t.exports=function(t){if(void 0==t)throw TypeError("Can't call method on "+t);return t}},function(t,n,e){var r=e(8),o=e(21);t.exports=Object.keys||function(t){return r(t,o)}},function(t,n,e){var r=e(9),o=e(10),i=e(13)(!1),u=e(17)("IE_PROTO");t.exports=function(t,n){var e,c=o(t),f=0,a=[];for(e in c)e!=u&&r(c,e)&&a.push(e);for(;n.length>f;)r(c,e=n[f++])&&(~i(a,e)||a.push(e));return a}},function(t,n){var e={}.hasOwnProperty;t.exports=function(t,n){return e.call(t,n)}},function(t,n,e){var r=e(11),o=e(6);t.exports=function(t){return r(o(t))}},function(t,n,e){var r=e(12);t.exports=Object("z").propertyIsEnumerable(0)?Object:function(t){return"String"==r(t)?t.split(""):Object(t)}},function(t,n){var e={}.toString;t.exports=function(t){return e.call(t).slice(8,-1)}},function(t,n,e){var r=e(10),o=e(14),i=e(16);t.exports=function(t){return function(n,e,u){var c,f=r(n),a=o(f.length),s=i(u,a);if(t&&e!=e){for(;a>s;)if(c=f[s++],c!=c)return!0}else for(;a>s;s++)if((t||s in f)&&f[s]===e)return t||s||0;return!t&&-1}}},function(t,n,e){var r=e(15),o=Math.min;t.exports=function(t){return t>0?o(r(t),9007199254740991):0}},function(t,n){var e=Math.ceil,r=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?r:e)(t)}},function(t,n,e){var r=e(15),o=Math.max,i=Math.min;t.exports=function(t,n){return t=r(t),t<0?o(t+n,0):i(t,n)}},function(t,n,e){var r=e(18)("keys"),o=e(20);t.exports=function(t){return r[t]||(r[t]=o(t))}},function(t,n,e){var r=e(19),o="__core-js_shared__",i=r[o]||(r[o]={});t.exports=function(t){return i[t]||(i[t]={})}},function(t,n){var e=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=e)},function(t,n){var e=0,r=Math.random();t.exports=function(t){return"Symbol(".concat(void 0===t?"":t,")_",(++e+r).toString(36))}},function(t,n){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},function(t,n,e){var r=e(23),o=e(24),i=e(33);t.exports=function(t,n){var e=(o.Object||{})[t]||Object[t],u={};u[t]=n(e),r(r.S+r.F*i(function(){e(1)}),"Object",u)}},function(t,n,e){var r=e(19),o=e(24),i=e(25),u=e(27),c="prototype",f=function(t,n,e){var a,s,l,p=t&f.F,d=t&f.G,y=t&f.S,v=t&f.P,h=t&f.B,m=t&f.W,b=d?o:o[n]||(o[n]={}),g=b[c],x=d?r:y?r[n]:(r[n]||{})[c];d&&(e=n);for(a in e)s=!p&&x&&void 0!==x[a],s&&a in b||(l=s?x[a]:e[a],b[a]=d&&"function"!=typeof x[a]?e[a]:h&&s?i(l,r):m&&x[a]==l?function(t){var n=function(n,e,r){if(this instanceof t){switch(arguments.length){case 0:return new t;case 1:return new t(n);case 2:return new t(n,e)}return new t(n,e,r)}return t.apply(this,arguments)};return n[c]=t[c],n}(l):v&&"function"==typeof l?i(Function.call,l):l,v&&((b.virtual||(b.virtual={}))[a]=l,t&f.R&&g&&!g[a]&&u(g,a,l)))};f.F=1,f.G=2,f.S=4,f.P=8,f.B=16,f.W=32,f.U=64,f.R=128,t.exports=f},function(t,n){var e=t.exports={version:"2.4.0"};"number"==typeof __e&&(__e=e)},function(t,n,e){var r=e(26);t.exports=function(t,n,e){if(r(t),void 0===n)return t;switch(e){case 1:return function(e){return t.call(n,e)};case 2:return function(e,r){return t.call(n,e,r)};case 3:return function(e,r,o){return t.call(n,e,r,o)}}return function(){return t.apply(n,arguments)}}},function(t,n){t.exports=function(t){if("function"!=typeof t)throw TypeError(t+" is not a function!");return t}},function(t,n,e){var r=e(28),o=e(36);t.exports=e(32)?function(t,n,e){return r.f(t,n,o(1,e))}:function(t,n,e){return t[n]=e,t}},function(t,n,e){var r=e(29),o=e(31),i=e(35),u=Object.defineProperty;n.f=e(32)?Object.defineProperty:function(t,n,e){if(r(t),n=i(n,!0),r(e),o)try{return u(t,n,e)}catch(c){}if("get"in e||"set"in e)throw TypeError("Accessors not supported!");return"value"in e&&(t[n]=e.value),t}},function(t,n,e){var r=e(30);t.exports=function(t){if(!r(t))throw TypeError(t+" is not an object!");return t}},function(t,n){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,n,e){t.exports=!e(32)&&!e(33)(function(){return 7!=Object.defineProperty(e(34)("div"),"a",{get:function(){return 7}}).a})},function(t,n,e){t.exports=!e(33)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,n){t.exports=function(t){try{return!!t()}catch(n){return!0}}},function(t,n,e){var r=e(30),o=e(19).document,i=r(o)&&r(o.createElement);t.exports=function(t){return i?o.createElement(t):{}}},function(t,n,e){var r=e(30);t.exports=function(t,n){if(!r(t))return t;var e,o;if(n&&"function"==typeof(e=t.toString)&&!r(o=e.call(t)))return o;if("function"==typeof(e=t.valueOf)&&!r(o=e.call(t)))return o;if(!n&&"function"==typeof(e=t.toString)&&!r(o=e.call(t)))return o;throw TypeError("Can't convert object to primitive value")}},function(t,n){t.exports=function(t,n){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:n}}},function(t,n,e){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}n.__esModule=!0;var o=e(38),i=r(o),u=e(58),c=r(u),f="function"==typeof c["default"]&&"symbol"==typeof i["default"]?function(t){return typeof t}:function(t){return t&&"function"==typeof c["default"]&&t.constructor===c["default"]?"symbol":typeof t};n["default"]="function"==typeof c["default"]&&"symbol"===f(i["default"])?function(t){return"undefined"==typeof t?"undefined":f(t)}:function(t){return t&&"function"==typeof c["default"]&&t.constructor===c["default"]?"symbol":"undefined"==typeof t?"undefined":f(t)}},function(t,n,e){t.exports={"default":e(39),__esModule:!0}},function(t,n,e){e(40),e(53),t.exports=e(57).f("iterator")},function(t,n,e){"use strict";var r=e(41)(!0);e(42)(String,"String",function(t){this._t=String(t),this._i=0},function(){var t,n=this._t,e=this._i;return e>=n.length?{value:void 0,done:!0}:(t=r(n,e),this._i+=t.length,{value:t,done:!1})})},function(t,n,e){var r=e(15),o=e(6);t.exports=function(t){return function(n,e){var i,u,c=String(o(n)),f=r(e),a=c.length;return f<0||f>=a?t?"":void 0:(i=c.charCodeAt(f),i<55296||i>56319||f+1===a||(u=c.charCodeAt(f+1))<56320||u>57343?t?c.charAt(f):i:t?c.slice(f,f+2):(i-55296<<10)+(u-56320)+65536)}}},function(t,n,e){"use strict";var r=e(43),o=e(23),i=e(44),u=e(27),c=e(9),f=e(45),a=e(46),s=e(50),l=e(52),p=e(51)("iterator"),d=!([].keys&&"next"in[].keys()),y="@@iterator",v="keys",h="values",m=function(){return this};t.exports=function(t,n,e,b,g,x,O){a(e,n,b);var S,w,_,j=function(t){if(!d&&t in M)return M[t];switch(t){case v:return function(){return new e(this,t)};case h:return function(){return new e(this,t)}}return function(){return new e(this,t)}},E=n+" Iterator",P=g==h,A=!1,M=t.prototype,T=M[p]||M[y]||g&&M[g],k=T||j(g),N=g?P?j("entries"):k:void 0,C="Array"==n?M.entries||T:T;if(C&&(_=l(C.call(new t)),_!==Object.prototype&&(s(_,E,!0),r||c(_,p)||u(_,p,m))),P&&T&&T.name!==h&&(A=!0,k=function(){return T.call(this)}),r&&!O||!d&&!A&&M[p]||u(M,p,k),f[n]=k,f[E]=m,g)if(S={values:P?k:j(h),keys:x?k:j(v),entries:N},O)for(w in S)w in M||i(M,w,S[w]);else o(o.P+o.F*(d||A),n,S);return S}},function(t,n){t.exports=!0},function(t,n,e){t.exports=e(27)},function(t,n){t.exports={}},function(t,n,e){"use strict";var r=e(47),o=e(36),i=e(50),u={};e(27)(u,e(51)("iterator"),function(){return this}),t.exports=function(t,n,e){t.prototype=r(u,{next:o(1,e)}),i(t,n+" Iterator")}},function(t,n,e){var r=e(29),o=e(48),i=e(21),u=e(17)("IE_PROTO"),c=function(){},f="prototype",a=function(){var t,n=e(34)("iframe"),r=i.length,o=">";for(n.style.display="none",e(49).appendChild(n),n.src="javascript:",t=n.contentWindow.document,t.open(),t.write("