关于本站
“最难不过坚持”
本人承接扒站仿站,php网站维护,病毒查杀,网站编辑,网站改版,html制作
有需要网站维护,改版,病毒查杀,网站编辑,网站备案,html制作等相关的工作可以联系我。
本人有多年相关工作经验,也可提供免费咨询,交个朋友。
有需要探讨问题的朋友,也可以加我微信,共同探讨!
微信:15011482830 QQ:408917339
2655
39
分类目录
最新评论
- https://jueru.net/
-
- :weixiao:
-
- :shuijiao: :weiqu: :zhenbang: :leng:
-
- :yiwen: :yiwen: :yiwen: :yiwen:
-
- 这个业务逻辑多少都有点奇怪了,阅读浏览次数增值在新闻详情页的控制器方法里setInc,这怎么还写进模型事件里了。如果非要用onAfterRead也可以,把新闻文章的内容单独分出来一个news_content表,然后把它和news做关联,然后给news_content表的onAfterRead事件做增值处理,这样点进新闻页内查询到文章内容时才会触发它。
-
文章标签更多
打开边栏(ESC)
关闭边栏(ESC)
vue-element-admin自定义svg-icon组件
1,安装svg-sprite-loader
npm i svg-sprite-loader2,配置svg-icon的全局组件。在components>SvgIcon下新建index.vue
<template> <svg :class="svgClass" aria-hidden="true"> <use :xlink:href="iconName" /> </svg> </template> <script> export default { name: "SvgIcon", props: { iconClass: { type: String, required: true }, className: { type: String, default: "" } }, computed: { iconName() { return `#icon-${this.iconClass}`; }, svgClass() { if (this.className) { return "svg-icon " + this.className; } else { return "svg-icon"; } } } }; </script> <style scoped> .svg-icon { width: 1em; height: 1em; vertical-align: -0.15em; fill: currentColor; overflow: hidden; } </style> 3,在src目录下新建icons目录,在icons目录下新建index.js及svg目录。index.js来注册全局组件。svg文件放在icons下的svg目录中。 index.js内容如下:
4,配置svg的loader,在vue.config.js中使用chainWebpack方法。参考vue官方的webpack相关配置及element-ui-vue的源码import Vue from "vue"; import SvgIcon from "@/components/SvgIcon"; // register globally Vue.component("svg-icon", SvgIcon); const req = require.context("./svg", false, /\.svg$/); const requireAll = requireContext => requireContext.keys().map(requireContext); requireAll(req);
"use strict"; const path = require("path"); function resolve(dir) { return path.join(__dirname, dir); } module.exports = { publicPath: "/", outputDir: "dist", assetsDir: "static", lintOnSave: process.env.NODE_ENV === "development", productionSourceMap: false, configureWebpack: { name: "G-test", resolve: { alias: { "@": resolve("src") } } }, chainWebpack(config) { config.plugins.delete("preload"); // TODO: need test config.plugins.delete("prefetch"); // TODO: need test config.module .rule("svg") .exclude.add(resolve("src/icons")) .end(); config.module .rule("icons") .test(/\.svg$/) .include.add(resolve("src/icons")) .end() .use("svg-sprite-loader") .loader("svg-sprite-loader") .options({ symbolId: "icon-[name]" }) .end(); config.module .rule("vue") .use("vue-loader") .loader("vue-loader") .tap(options => { options.compilerOptions.preserveWhitespace = true; return options; }) .end(); config // https://webpack.js.org/configuration/devtool/#development .when(process.env.NODE_ENV === "development", config => config.devtool("cheap-source-map") ); config.when(process.env.NODE_ENV !== "development", config => { config .plugin("ScriptExtHtmlWebpackPlugin") .after("html") .use("script-ext-html-webpack-plugin", [ { // `runtime` must same as runtimeChunk name. default is `runtime` inline: /runtime\..*\.js$/ } ]) .end(); config.optimization.splitChunks({ chunks: "all", cacheGroups: { libs: { name: "chunk-libs", test: /[\\/]node_modules[\\/]/, priority: 10, chunks: "initial" // only package third parties that are initially dependent }, elementUI: { name: "chunk-elementUI", // split elementUI into a single package priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm }, commons: { name: "chunk-commons", test: resolve("src/components"), // can customize your rules minChunks: 3, // minimum common number priority: 5, reuseExistingChunk: true } } }); config.optimization.runtimeChunk("single"); }); } };5,在main.js中引入icons
import "./icons";
6,此时可以在全局中使用组件
<span class="svg-container"> <svg-icon icon-class="user" /> </span>
4,配置svg的loader,在vue.config.js中使用chainWebpack方法,自己改的也能用
const { defineConfig } = require('@vue/cli-service') const path = require('path') function resolve(dir) { return path.join(__dirname, dir) } module.exports = defineConfig({ transpileDependencies: true, lintOnSave:false, chainWebpack(config) { // set svg-sprite-loader config.module .rule('svg') .exclude.add(resolve('src/icons')) .end() config.module .rule('icons') .test(/\.svg$/) .include.add(resolve('src/icons')) .end() .use('svg-sprite-loader') .loader('svg-sprite-loader') .options({ symbolId: 'icon-[name]' }) .end() } })
赏
相关推荐
接口返回request failed with status code 500错误
接口返回request failed with status code 500错误
登录界面,验证账号密码成功,但是返回500错误
可能原因:linux服务器,用tp5搭建的后台及接口,会生成一部分缓存文件,但是linux默认没有权限创建数据,所以,只要在缓存文件夹runtime添加写的权限即可
解决errors and 0 warnings potentially fixable with the `--fix` option.问题
解决errors and 0 warnings potentially fixable with the `--fix` option.问题
项目正常运行,就是有这个提示
找到.eslintrc.js注释掉// 'eslint:recommended'
评论加载中...