<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vue &#8211; 「马马虎虎」</title>
	<atom:link href="https://www.gek6.cn/category/web-front-end/vue/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.gek6.cn</link>
	<description>极客蜗牛-开发效率很慢的...</description>
	<lastBuildDate>Tue, 04 Jul 2023 07:08:25 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>

<image>
	<url>https://www.gek6.cn/wp-content/uploads/2021/12/20211205200322145-32x32.png</url>
	<title>Vue &#8211; 「马马虎虎」</title>
	<link>https://www.gek6.cn</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>vue3+vite自动加载路由</title>
		<link>https://www.gek6.cn/vue3vite%e8%87%aa%e5%8a%a8%e5%8a%a0%e8%bd%bd%e8%b7%af%e7%94%b1/</link>
					<comments>https://www.gek6.cn/vue3vite%e8%87%aa%e5%8a%a8%e5%8a%a0%e8%bd%bd%e8%b7%af%e7%94%b1/#respond</comments>
		
		<dc:creator><![CDATA[lane]]></dc:creator>
		<pubDate>Fri, 29 Jul 2022 02:54:52 +0000</pubDate>
				<category><![CDATA[Vue]]></category>
		<guid isPermaLink="false">https://www.gek6.cn/?p=108</guid>

					<description><![CDATA[1、使用 import.meta&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<h3>1、使用 <code>import.meta.glob</code>加载所有vue文件</h3>
<pre><code>const modules = import.meta.glob(&quot;../views/**/*.vue&quot;);
let autoRoutes: Route[] = [];
for (let key in modules) {
  console.log(key);
  autoRoutes.push({
    filePath: key,
    path: key.replace(&quot;../views/&quot;, &quot;/&quot;).replace(&quot;.vue&quot;, &quot;&quot;),
    component: modules[key]
  });
}</code></pre>
<h3>2、使用<code>addRoute</code>挂载动态路由</h3>
<pre><code>const mountRoutes = async () =&gt; {
  for (const item of autoRoutes) {
    if (item.path) {
      const route = {
        path: item.path,
        component: () =&gt; import(item.filePath)
      };
      console.log(route);
      router.addRoute(route);
    }
  }
};</code></pre>
<h3>3、路由配置</h3>
<pre><code>import { createRouter, createWebHashHistory } from &quot;vue-router&quot;;
import indexPage from &quot;../views/index/index.vue&quot;;
import { mountRoutes } from &quot;./auto-load&quot;;
import { getToken } from &quot;../utils/token&quot;;

const routes = [
  { path: &quot;/&quot;, component: indexPage },
  { path: &quot;/login&quot;, component: () =&gt; import(&quot;../views-common/account/login/index.vue&quot;) }
];
export const router = createRouter({
  history: createWebHashHistory(),
  routes
});

const authWhiteList = [
  &quot;/login&quot;
];
// 是否已经挂载动态路由标识
let routeHasMounted = false;
router.beforeEach(async (to, from, next) =&gt; {
  // 是否为免登录白名单 是的话直接放行
  if (authWhiteList.includes(to.path)) {
    next();
  } else {
    // 需要免登录的页面 判断是否已经登录
    if (!getToken()) {
      // 未登录的直接跳转到登录页面
      next({ path: &quot;/login&quot;, replace: true });
    } else {
      // 已经登录的 判断是否挂载动态路由
      if (!routeHasMounted) {
        // 未挂载状态 挂载动态路由
        await mountRoutes();
        // 将挂载状态设置为true
        routeHasMounted = true;
        // 重新路由到当前页面 因为此页面在第一次打开的时候是 匹配不到路由的
        // 这里replace: true 是为了让网页不能返回上一页
        next({ ...to, replace: true });
      } else {
        // 已经挂载状态 直接放行
        next();
      }
    }
  }
});
</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gek6.cn/vue3vite%e8%87%aa%e5%8a%a8%e5%8a%a0%e8%bd%bd%e8%b7%af%e7%94%b1/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>vue-quill-editor 添加自定义上传图片功能（上传至服务器或七牛云）</title>
		<link>https://www.gek6.cn/vue-quill-editor-%e6%b7%bb%e5%8a%a0%e8%87%aa%e5%ae%9a%e4%b9%89%e4%b8%8a%e4%bc%a0%e5%9b%be%e7%89%87%e5%8a%9f%e8%83%bd%ef%bc%88%e4%b8%8a%e4%bc%a0%e8%87%b3%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%88%96%e4%b8%83/</link>
					<comments>https://www.gek6.cn/vue-quill-editor-%e6%b7%bb%e5%8a%a0%e8%87%aa%e5%ae%9a%e4%b9%89%e4%b8%8a%e4%bc%a0%e5%9b%be%e7%89%87%e5%8a%9f%e8%83%bd%ef%bc%88%e4%b8%8a%e4%bc%a0%e8%87%b3%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%88%96%e4%b8%83/#respond</comments>
		
		<dc:creator><![CDATA[lane]]></dc:creator>
		<pubDate>Sun, 05 Dec 2021 11:36:23 +0000</pubDate>
				<category><![CDATA[Vue]]></category>
		<guid isPermaLink="false">https://www.gek6.cn/?p=53</guid>

					<description><![CDATA[vue-quill-editor&#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<blockquote>
<p>vue-quill-editor 默认的是以base64保存图片，会直接把图片base64和内容文本一同以字符串的形式提交到后端。 现在这样不科学</p>
</blockquote>
<h5>安装 vue-quill-editor</h5>
<pre><code>npm i vue-quill-editor --save</code></pre>
<blockquote>
<p>富文本示例代码<br />
<a href="https://github.com/gek6/letou_hr/blob/master/letou_admin_web/src/views/rich_text/rich_text.vue">https://github.com/gek6/letou_hr/blob/master/letou_admin_web/src/views/rich_text/rich_text.vue</a><br />
图片直传七牛云<br />
<a href="https://github.com/gek6/letou_hr/blob/master/letou_admin_web/src/api/upload.js">https://github.com/gek6/letou_hr/blob/master/letou_admin_web/src/api/upload.js</a></p>
</blockquote>
<h5>思路</h5>
<ul>
<li>用自定义的方法代替quill-editor中的图片点击事件</li>
<li>点击上传图片的icon后，去触发file类型 input 的点击事件，选择图片。（我这用的是饿了么的上传组件，上传到七牛云我已经写好了）</li>
<li>监听input的 onchange 拿到选择的文件数据，然后是要上传到自己服务器呢 还是上传到七牛云 就随意了。</li>
<li>上传完成以后 将图片的远程路径 添加到富文本内容区域<br />
<h5>页面内引入</h5>
<pre><code>import &#039;quill/dist/quill.core.css&#039;
import &#039;quill/dist/quill.snow.css&#039;
import &#039;quill/dist/quill.bubble.css&#039;
import { quillEditor } from &#039;vue-quill-editor&#039;
//注册组件
components: {
quillEditor
},</code></pre>
</li>
</ul>
<pre><code>&lt;div class=&quot;rich_box&quot;&gt;
    &lt;!--富文本组件--&gt;
    &lt;quill-editor v-model=&quot;content&quot; ref=&quot;myQuillEditor&quot; :options=&quot;options&quot;&gt;&lt;/quill-editor&gt;
&lt;/div&gt;
&lt;!--饿了么上传组件，也可以用input代替，都是隐藏起来--&gt;
&lt;el-upload
    class=&quot;avatar-uploader&quot;
    action=&quot;&quot;
    :http-request=&quot;to_upload_img&quot;
    :show-file-list=&quot;false&quot;
    style=&quot;display: none&quot;
    &gt;
    &lt;i class=&quot;el-icon-plus avatar-uploader-icon&quot; id=&quot;imgInput&quot;&gt;&lt;/i&gt;
&lt;/el-upload&gt;
</code></pre>
<h5>添加自定义方法</h5>
<pre><code>//mounted钩子中 替换插件图标点击事件
// 为图片ICON绑定事件  getModule 为编辑器的内部属性
this.$refs.myQuillEditor.quill.getModule(&#039;toolbar&#039;).addHandler(&#039;image&#039;, this.imgHandler)</code></pre>
<pre><code>// 点击图片ICON触发事件
imgHandler(state) {
  console.log(state)
  this.addRange = this.$refs.myQuillEditor.quill.getSelection()
  if (state) {
    // let fileInput = document.getElementById(&#039;imgInput&#039;)
    // fileInput.click() // 加一个触发事件
    // 选择并上传一张图片
    let fileInput = document.getElementById(&#039;imgInput&#039;)
    fileInput.click() // 加一个触发事件
  }
},</code></pre>
<pre><code>to_upload_img(formdata){
  return new Promise((resolve,reject)=&gt;{
    upload_img(formdata).then(res=&gt;{
      // 图片的远程路径
      let value = res.key;
      // 将图片添加到富文本内容区域
      this.addRange = this.$refs.myQuillEditor.quill.getSelection();
      // 调用编辑器的 insertEmbed 方法，插入URL
      this.$refs.myQuillEditor.quill.insertEmbed(this.addRange !== null ? this.addRange.index : 0, &#039;image&#039;, value, Quill.sources.USER)   

    })
  })
}</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gek6.cn/vue-quill-editor-%e6%b7%bb%e5%8a%a0%e8%87%aa%e5%ae%9a%e4%b9%89%e4%b8%8a%e4%bc%a0%e5%9b%be%e7%89%87%e5%8a%9f%e8%83%bd%ef%bc%88%e4%b8%8a%e4%bc%a0%e8%87%b3%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%88%96%e4%b8%83/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
