" on the index page; 2. Set the cache name to "test -keep-alive"; 3. Configure "{path: '/Material',name: 'Material'...}" in the router file."/> " on the index page; 2. Set the cache name to "test -keep-alive"; 3. Configure "{path: '/Material',name: 'Material'...}" in the router file.">

Home  >  Article  >  Web Front-end  >  What should I do if the vue menu does not refresh?

What should I do if the vue menu does not refresh?

藏色散人
藏色散人Original
2022-12-26 16:36:422674browse

Solution to vue menu not refreshing: 1. Write "99df3d3b411e1be071f4ada3d31f1e18dd6e4ababe59793a4ac75fb9e5c5550e" on the index page; 2. Set the cache name to "test-keep-alive"; 3. Configure "{path: '/Material',name: 'Material'...}" in the router file.

What should I do if the vue menu does not refresh?

#The operating environment of this tutorial: Windows 10 system, Vue version 3, Dell G3 computer.

What should I do if the vue menu does not refresh?

vue implements component switching tab (menu) page without refreshing the page

vue implements component switching tab (menu) page without refreshing the page (keep alive)

7c9485ff8c3cba5ae9343ed63c2dc3f7 is a built-in component of Vue, which can retain the state in the memory during component switching to prevent repeated rendering of the DOM.

Official website explanation

7c9485ff8c3cba5ae9343ed63c2dc3f7When wrapping dynamic components, inactive component instances will be cached instead of destroying them. Similar to , is an abstract component: it does not render a DOM element by itself, nor does it appear in the parent component chain. When a component is switched within , its two life cycle hook functions, activated and deactivated, will be executed accordingly. In 2.2.0 and higher, activated and deactivated will fire on all nested components within the tree. Mainly used to preserve component state or avoid re-rendering.

Application Scenario

For example, when building a system with the function of switching components, labels are usually placed on the index page, plus the parent-child configuration of the router file. Component relationships and routing jumps enable component rendering of pages. But the effect of this is that every time the component is clicked, the page will be re-rendered, and the data on the page will not be retained. Therefore, using the 7c9485ff8c3cba5ae9343ed63c2dc3f7 tag wrapped with the 62fd61a4bda39e5f3eeccf86eb0f077c tag can cache inactive components and still have the original information after returning.

Specific code

Write the following code on the index page

// 需要缓存的组件
<keep-alive v-if="showView">
    <router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
// 不需要缓存的组件
<router-view v-if="!$route.meta.keepAlive"></router-view>

The cache component name is the component test-keep-alive, and the include here is cache. , exclude is not cached

// 将缓存name为test-keep-alive的组件
<keep-alive include="test-keep-alive">
  <component></component>
</keep-alive>
// 将缓存name为teat,teat2的组件
<keep-alive include="teat,teat2">
  <component></component>
</keep-alive>

Configure the following code in the router file

// 需要缓存的组件
{
    path: &#39;/Material&#39;,
    name: &#39;Material&#39;,
    aliasName: &#39;物料信息&#39;,
    meta:{keepAlive: true}, // 是否缓存组件
    component: () => import(&#39;../components/Material/index.vue&#39;),
},
{
    path: &#39;/Unit&#39;,
    name: &#39;Unit&#39;,
    aliasName: &#39;单位信息&#39;,
    component: () => import(&#39;../components/Unit/index.vue&#39;),
}

Recommended learning: "vue.js Video Tutorial"

The above is the detailed content of What should I do if the vue menu does not refresh?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn