FEMessage / vant

Lightweight Mobile UI Components built on Vue
https://femessage.github.io/vant/#/zh-CN/intro
MIT License
0 stars 6 forks source link

[website]: 文档搜索会跳转到原 有赞 文档 #11

Open eviIIt opened 4 years ago

eviIIt commented 4 years ago

文档搜索功能点击搜索结果会跳转到有赞的文档.

相关内容

估计需要申请 algolia 账号以及提 pr 到 docsearch-configs

xrr2016 commented 4 years ago

原因

搜索结果中的一项是一个跳转到 https://youzan.github.io/vant a 链接

result

vant 的文档实例化了一个docsearch 对象,搜索结果的 UI 是通过 docsearch 这个实例对象创建出来的。

 mounted() {
    if (this.searchConfig) {
      this.docsearchInstance = window.docsearch({
        ...this.searchConfig,
        inputSelector: '.van-doc-search',
        algoliaOptions: {
          facetFilters: [`lang:${this.lang}`]
        }
      });
    }
  }

SearchInput

而element-ui 的文档的搜索结果是用自己的 autocomplete 组件显示的,点击搜索结果执行 handleSelect 方法

handleSelect

这个方法直接跳转网站内路由,所以不会跳转到 element 官方的文档网站去

解决方案

Docsearch 申请一个 apiKey

image

使用申请到的 key 替换原来的

export const searchConfig = {
  apiKey: '90067aecdaa2c85220e2783cd305caac',
  indexName: 'vant'
};
  1. 使用 docssearch 提供的搜索结果 ui dropdown

  2. 像 element-ui 那样自己开发一个结果展示的 UI