View 间链接和跳转


让我们看一种更复杂一点的情况

我们有两个已经初始化完成的View(left view 和 right view)。这种情况下,所有在left view 中的链接加载的页面都会放在 left view 中,所有在right view中的链接加载的页面都会放在 right view中。

但是我们现在需要一些在 left view 中的链接加载的页面放进 right view中。这叫 View间链接。我们已经知道可以通过JS来实现,通过 .router.load().router.back()方法。

Framework7 可以让我们不使用JS来实现,所有需要做的只是在连接上增加一个 data-view 属性,这个属性包含一个CSS选择器指向需要放入的那个View即可。

  1. <body>
  2.   ...
  3.   <!-- Views -->
  4.   <div class="views">
  5.     <!-- Left view -->
  6.     <div class="view view-main left-view">
  7.       <!-- Pages -->
  8.       
  9.         <!-- These links will load pages to this Left view -->
  10.         <a href="about.html"> About </a>
  11.         <a href="services.html"> Services </a>
  12.         
  13.         <!-- This link will load pages to Right view -->
  14.         <a href="products.html" data-view=".right-view"> Products </a>
  15.     </div>
  16.     <!-- Right view -->
  17.     <div class="view right-view">
  18.       <!-- Pages -->
  19.       
  20.         <!-- These links will load pages to this Right view -->
  21.         <a href="products.html"> Products </a>
  22.         <a href="contacts.html"> Contacts </a>
  23.         
  24.         <!-- This link will load pages to Left view -->
  25.         <a href="about.html" data-view=".left-view"> About </a>
  26.         <a href="services.html" data-view=".left-view"> Services </a>
  27.         
  28.         <!-- This link will trigger Go Back in Left view -->
  29.         <a href="#" class="back" data-view=".left-view"> About </a>
  30.     </div>          
  31.   </div>
  32.   ...
  33. </body>

 下一步

我们已经有了完整的页面结构,下一步就是使用组件。首先从最重要的组件开始,导航栏和工具栏