Skip to content

Commit d8e3b94

Browse files
committed
Site updated: 2016-09-18 14:49:26
1 parent 1386ba2 commit d8e3b94

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

api/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,8 +1273,10 @@ <h3 id="transition-group"><a href="#transition-group" class="headerlink" title="
12731273
<h3 id="keep-alive"><a href="#keep-alive" class="headerlink" title="keep-alive"></a>keep-alive</h3><ul>
12741274
<li><p><strong>Usage:</strong></p>
12751275
<p>When wrapped around a dynamic component, <code>&lt;keep-alive&gt;</code> caches the inactive component instances without destroying them. Similar to <code>&lt;transition&gt;</code>, <code>&lt;keep-alive&gt;</code> is an abstract component: it doesn’t render a DOM element itself, and doesn’t show up in the component parent chain.</p>
1276+
<p>When a component is toggled inside <code>&lt;keep-alive&gt;</code>, its <code>activated</code> and <code>deactivated</code> lifecycle hooks will be invoked accordingly.</p>
12761277
<p>Primarily used with preserve component state or avoid re-rendering.</p>
12771278
<figure class="highlight html"><table><tr><td class="code"><pre><div class="line"><span class="comment">&lt;!-- basic --&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">keep-alive</span>&gt;</span></div><div class="line"> <span class="tag">&lt;<span class="name">component</span> <span class="attr">:is</span>=<span class="string">"view"</span>&gt;</span><span class="tag">&lt;/<span class="name">component</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">keep-alive</span>&gt;</span></div><div class="line"></div><div class="line"><span class="comment">&lt;!-- multiple conditional children --&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">keep-alive</span>&gt;</span></div><div class="line"> <span class="tag">&lt;<span class="name">comp-a</span> <span class="attr">v-if</span>=<span class="string">"a &gt; 1"</span>&gt;</span><span class="tag">&lt;/<span class="name">comp-a</span>&gt;</span></div><div class="line"> <span class="tag">&lt;<span class="name">comp-b</span> <span class="attr">v-else</span>&gt;</span><span class="tag">&lt;/<span class="name">comp-b</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">keep-alive</span>&gt;</span></div><div class="line"></div><div class="line"><span class="comment">&lt;!-- used together with &lt;transition&gt; --&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">transition</span>&gt;</span></div><div class="line"> <span class="tag">&lt;<span class="name">keep-alive</span>&gt;</span></div><div class="line"> <span class="tag">&lt;<span class="name">component</span> <span class="attr">:is</span>=<span class="string">"view"</span>&gt;</span><span class="tag">&lt;/<span class="name">component</span>&gt;</span></div><div class="line"> <span class="tag">&lt;/<span class="name">keep-alive</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">transition</span>&gt;</span></div></pre></td></tr></table></figure>
1279+
<p class="tip"><code>&lt;keep-alive&gt;</code> does not work with functional components because they do not have instances to be cached.</p>
12781280
</li>
12791281
<li><p><strong>See also:</strong> <a href="/guide/components.html#keep-alive">Dynamic Components - keep-alive</a></p>
12801282
</li>

guide/components.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,9 @@ <h2 id="Dynamic-Components"><a href="#Dynamic-Components" class="headerlink" tit
669669
<figure class="highlight html"><table><tr><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">component</span> <span class="attr">v-bind:is</span>=<span class="string">"currentView"</span>&gt;</span></div><div class="line"> <span class="comment">&lt;!-- component changes when vm.currentView changes! --&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">component</span>&gt;</span></div></pre></td></tr></table></figure>
670670
<p>If you prefer, you can also bind directly to component objects:</p>
671671
<figure class="highlight js"><table><tr><td class="code"><pre><div class="line"><span class="keyword">var</span> Home = &#123;</div><div class="line"> template: <span class="string">'&lt;p&gt;Welcome home!&lt;/p&gt;'</span></div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="keyword">new</span> Vue(&#123;</div><div class="line"> el: <span class="string">'body'</span>,</div><div class="line"> data: &#123;</div><div class="line"> currentView: Home</div><div class="line"> &#125;</div><div class="line">&#125;)</div></pre></td></tr></table></figure>
672-
<h3 id="keep-alive"><a href="#keep-alive" class="headerlink" title="keep-alive"></a><code>keep-alive</code></h3><p>If you want to keep the switched-out components in memory so that you can preserve their state or avoid re-rendering, you can wrap a dynamic component in a <code>keep-alive</code> element:</p>
672+
<h3 id="keep-alive"><a href="#keep-alive" class="headerlink" title="keep-alive"></a><code>keep-alive</code></h3><p>If you want to keep the switched-out components in memory so that you can preserve their state or avoid re-rendering, you can wrap a dynamic component in a <code>&lt;keep-alive&gt;</code> element:</p>
673673
<figure class="highlight html"><table><tr><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">keep-alive</span>&gt;</span></div><div class="line"> <span class="tag">&lt;<span class="name">component</span> <span class="attr">:is</span>=<span class="string">"currentView"</span>&gt;</span></div><div class="line"> <span class="comment">&lt;!-- inactive components will be cached! --&gt;</span></div><div class="line"> <span class="tag">&lt;/<span class="name">component</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">keep-alive</span>&gt;</span></div></pre></td></tr></table></figure>
674+
<p>Check out more details on <code>&lt;keep-alive&gt;</code> in the <a href="/api/#keep-alive">API reference</a>.</p>
674675
<h2 id="Misc"><a href="#Misc" class="headerlink" title="Misc"></a>Misc</h2><h3 id="Authoring-Reusable-Components"><a href="#Authoring-Reusable-Components" class="headerlink" title="Authoring Reusable Components"></a>Authoring Reusable Components</h3><p>When authoring components, it’s good to keep in mind whether you intend to reuse it somewhere else later. It’s OK for one-off components to be tightly coupled, but reusable components should define a clean public interface and make no assumptions about the context it’s used in.</p>
675676
<p>The API for a Vue component comes in three parts - props, events, and slots:</p>
676677
<ul>

guide/migration.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,14 +434,14 @@ <h4>Upgrade Path</h4>
434434
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper" target="_blank" rel="external">migration helper</a> on your codebase to find all examples of this hook.</p>
435435
</div>
436436

437-
<h2 id="v-for"><a href="#v-for" class="headerlink" title="v-for"></a><code>v-for</code></h2><h3 id="v-for-Argument-Order-for-Arrays"><a href="#v-for-Argument-Order-for-Arrays" class="headerlink" title="v-for Argument Order for Arrays"></a><code>v-for</code> Argument Order for Arrays</h3><p>When including an <code>index</code>, the argument order for arrays used to be <code>(index, value)</code>. It is now <code>(value, index)</code> to be more consisent with JavaScript’s native array methods such as <code>forEach</code> and <code>map</code>.</p>
437+
<h2 id="v-for"><a href="#v-for" class="headerlink" title="v-for"></a><code>v-for</code></h2><h3 id="v-for-Argument-Order-for-Arrays"><a href="#v-for-Argument-Order-for-Arrays" class="headerlink" title="v-for Argument Order for Arrays"></a><code>v-for</code> Argument Order for Arrays</h3><p>When including an <code>index</code>, the argument order for arrays used to be <code>(index, value)</code>. It is now <code>(value, index)</code> to be more consistent with JavaScript’s native array methods such as <code>forEach</code> and <code>map</code>.</p>
438438

439439
<div class="upgrade-path">
440440
<h4>Upgrade Path</h4>
441441
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper" target="_blank" rel="external">migration helper</a> on your codebase to find examples of the deprecated argument order. Note that if you name your index arguments something unusual like <code>position</code> or <code>num</code>, the helper will not flag them.</p>
442442
</div>
443443

444-
<h3 id="v-for-Argument-Order-for-Objects"><a href="#v-for-Argument-Order-for-Objects" class="headerlink" title="v-for Argument Order for Objects"></a><code>v-for</code> Argument Order for Objects</h3><p>When including a <code>key</code>, the argument order for objects used to be <code>(key, value)</code>. It is now <code>(value, key)</code> to be more consisent with common object iterators such as lodash’s.</p>
444+
<h3 id="v-for-Argument-Order-for-Objects"><a href="#v-for-Argument-Order-for-Objects" class="headerlink" title="v-for Argument Order for Objects"></a><code>v-for</code> Argument Order for Objects</h3><p>When including a <code>key</code>, the argument order for objects used to be <code>(key, value)</code>. It is now <code>(value, key)</code> to be more consistent with common object iterators such as lodash’s.</p>
445445

446446
<div class="upgrade-path">
447447
<h4>Upgrade Path</h4>
@@ -606,7 +606,7 @@ <h4>Upgrade Path</h4>
606606
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper" target="_blank" rel="external">migration helper</a> on your codebase to find examples of the these deprecated param attributes.</p>
607607
</div>
608608

609-
<h3 id="v-model-with-Inline-value-deprecated"><a href="#v-model-with-Inline-value-deprecated" class="headerlink" title="v-model with Inline value deprecated"></a><code>v-model</code> with Inline <code>value</code> <sup>deprecated</sup></h3><p><code>v-model</code> no longer cares about initial value of an inline <code>value</code> attribute. For predictability, it will instead always treat the Vue instance data as the source of truth.</p>
609+
<h3 id="v-model-with-Inline-value-deprecated"><a href="#v-model-with-Inline-value-deprecated" class="headerlink" title="v-model with Inline value deprecated"></a><code>v-model</code> with Inline <code>value</code> <sup>deprecated</sup></h3><p><code>v-model</code> no longer cares about the initial value of an inline <code>value</code> attribute. For predictability, it will instead always treat the Vue instance data as the source of truth.</p>
610610
<p>That means this element:</p>
611611
<figure class="highlight html"><table><tr><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">v-model</span>=<span class="string">"text"</span> <span class="attr">value</span>=<span class="string">"foo"</span>&gt;</span></div></pre></td></tr></table></figure>
612612
<p>backed by this data:</p>
@@ -643,7 +643,7 @@ <h4>Upgrade Path</h4>
643643
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper" target="_blank" rel="external">migration helper</a> on your codebase to find examples of style bindings with <code>!important</code> in objects.</p>
644644
</div>
645645

646-
<h3 id="v-el-and-v-ref-deprecated"><a href="#v-el-and-v-ref-deprecated" class="headerlink" title="v-el and v-ref deprecated"></a><code>v-el</code> and <code>v-ref</code> <sup>deprecated</sup></h3><p>For simplicity, <code>v-el</code> and <code>v-ref</code> have been merged into the <code>ref</code> attribute, accessable on a component instance via <code>$refs</code>. That means <code>v-el:my-element</code> would become <code>ref=&quot;myElement&quot;</code> and <code>v-ref:my-component</code> would become <code>ref=&quot;myComponent&quot;</code>. When used on a normal element, the <code>ref</code> will be the DOM element, and when used on a component, the <code>ref</code> will be the component instance.</p>
646+
<h3 id="v-el-and-v-ref-deprecated"><a href="#v-el-and-v-ref-deprecated" class="headerlink" title="v-el and v-ref deprecated"></a><code>v-el</code> and <code>v-ref</code> <sup>deprecated</sup></h3><p>For simplicity, <code>v-el</code> and <code>v-ref</code> have been merged into the <code>ref</code> attribute, accessible on a component instance via <code>$refs</code>. That means <code>v-el:my-element</code> would become <code>ref=&quot;myElement&quot;</code> and <code>v-ref:my-component</code> would become <code>ref=&quot;myComponent&quot;</code>. When used on a normal element, the <code>ref</code> will be the DOM element, and when used on a component, the <code>ref</code> will be the component instance.</p>
647647
<p>Since <code>v-ref</code> is no longer a directive, but a special attribute, it can also be dynamically defined. This is especially useful in combination with <code>v-for</code>. For example:</p>
648648
<figure class="highlight html"><table><tr><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">v-for</span>=<span class="string">"item in items"</span> <span class="attr">v-bind:ref</span>=<span class="string">"'item' + item.id"</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></div></pre></td></tr></table></figure>
649649
<p>Previously, <code>v-el</code>/<code>v-ref</code> combined with <code>v-for</code> would produce an array of elements/components, because there was no way to give each item a unique name. You can still achieve this behavior by given each item the same <code>ref</code>:</p>
@@ -702,7 +702,7 @@ <h4>Upgrade Path</h4>
702702
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper" target="_blank" rel="external">migration helper</a> on your codebase to find examples of the the old <code>keyCode</code> configuration syntax.</p>
703703
</div>
704704

705-
<h3 id="dispatch-and-broadcast-deprecated"><a href="#dispatch-and-broadcast-deprecated" class="headerlink" title="$dispatch and $broadcast deprecated"></a><code>$dispatch</code> and <code>$broadcast</code> <sup>deprecated</sup></h3><p><code>$dispatch</code> and <code>$broadcast</code> are being deprecated in favor of more explicity cross-component communication and more maintainable state management solutions, such as <a href="https://github.com/vuejs/vuex" target="_blank" rel="external">Vuex</a>.</p>
705+
<h3 id="dispatch-and-broadcast-deprecated"><a href="#dispatch-and-broadcast-deprecated" class="headerlink" title="$dispatch and $broadcast deprecated"></a><code>$dispatch</code> and <code>$broadcast</code> <sup>deprecated</sup></h3><p><code>$dispatch</code> and <code>$broadcast</code> are being deprecated in favor of more explicitly cross-component communication and more maintainable state management solutions, such as <a href="https://github.com/vuejs/vuex" target="_blank" rel="external">Vuex</a>.</p>
706706
<p>The problem is event flows that depend on a component’s tree structure can be hard to reason about and very brittle when the tree becomes large. It simply doesn’t scale well and we don’t want to set you up for pain later. <code>$dispatch</code> and <code>$broadcast</code> also do not solve communication between sibling components.</p>
707707
<p>For the simplest possible upgrade from <code>$dispatch</code> and <code>$broadcast</code>, you can use a centralized event hub that allows components to communicate no matter where they are in the component tree. Because Vue instances implement an event emitter interface, you can actually use an empty Vue instance for this purpose.</p>
708708
<p>For example, let’s say we have a todo app structured like this:</p>
@@ -739,7 +739,7 @@ <h4 id="Replacing-the-filterBy-Filter"><a href="#Replacing-the-filterBy-Filter"
739739
<p>Use JavaScript’s built-in <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#Examples" target="_blank" rel="external"><code>.filter</code> method</a> in a computed property:</p>
740740
<figure class="highlight html"><table><tr><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">v-for</span>=<span class="string">"user in filteredUsers"</span>&gt;</span>&#123;&#123; user.name &#125;&#125;<span class="tag">&lt;/<span class="name">p</span>&gt;</span></div></pre></td></tr></table></figure>
741741
<figure class="highlight js"><table><tr><td class="code"><pre><div class="line">computed: &#123;</div><div class="line"> filteredUsers: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</div><div class="line"> <span class="keyword">return</span> <span class="keyword">this</span>.users.filter(<span class="function"><span class="keyword">function</span> (<span class="params">user</span>) </span>&#123;</div><div class="line"> <span class="keyword">return</span> user.name.indexOf(<span class="keyword">this</span>.searchQuery)</div><div class="line"> &#125;)</div><div class="line"> &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
742-
<p>With JavaScript’s native <code>.filter</code>, it’s also manage much more complex filtering operations, because you have access to the full power of JavaScript within computed properties. For example, if you wanted to find all active users and case-insensitively match against both their name and email:</p>
742+
<p>JavaScript’s native <code>.filter</code> can also manage much more complex filtering operations, because you have access to the full power of JavaScript within computed properties. For example, if you wanted to find all active users and case-insensitively match against both their name and email:</p>
743743
<figure class="highlight js"><table><tr><td class="code"><pre><div class="line"><span class="keyword">this</span>.users.filter(<span class="function"><span class="keyword">function</span> (<span class="params">user</span>) </span>&#123;</div><div class="line"> <span class="keyword">var</span> searchRegex = <span class="keyword">new</span> <span class="built_in">RegExp</span>(<span class="keyword">this</span>.searchQuery, <span class="string">'i'</span>)</div><div class="line"> <span class="keyword">return</span> user.isActive &amp;&amp; (</div><div class="line"> searchRegex.test(user.name) ||</div><div class="line"> searchRegex.test(user.email)</div><div class="line"> )</div><div class="line">&#125;)</div></pre></td></tr></table></figure>
744744
<h4 id="Replacing-the-orderBy-Filter"><a href="#Replacing-the-orderBy-Filter" class="headerlink" title="Replacing the orderBy Filter"></a>Replacing the <code>orderBy</code> Filter</h4><p>Instead of:</p>
745745
<figure class="highlight html"><table><tr><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">v-for</span>=<span class="string">"user in users | orderBy 'name'"</span>&gt;</span>&#123;&#123; user.name &#125;&#125;<span class="tag">&lt;/<span class="name">p</span>&gt;</span></div></pre></td></tr></table></figure>

0 commit comments

Comments
 (0)