.vue 单文件组件中使用的基础问题
Issue with foundation used in .vue single file components
我意识到在失败的组件内部使用 Zurb Foundation classes in .vue single file components. At first I could not get a Reveal Modal to work inside the .vue component
but it was working when I use the same code in a blade
or html
file. Then I noticed a pattern because when I tried to use the Foundation's Orbit 时存在问题,起初我认为这是一个错误,但后来我在 blade
文件中使用了相同的代码并且有效。其他基础 类,例如 row
、grid
和 buttons
工作正常。
有没有人遇到过同样的问题?我该如何解决?
模态代码如下:
<a data-open="video" class="button warning" href="">WATCH VIDEO</a>
<div id="video" class="reveal" data-reveal>
<div class="lead">
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="flex-video">
<iframe width="1280" height="720" :src="url" frameborder="0" allowfullscreen></iframe>
</div>
</div>
对于轨道,我使用了基础文档中的基本示例进行测试。
<div class="orbit" role="region" aria-label="Favorite Space Pictures" data-orbit>
<ul class="orbit-container">
<button class="orbit-previous"><span class="show-for-sr">Previous Slide</span>◀︎</button>
<button class="orbit-next"><span class="show-for-sr">Next Slide</span>▶︎</button>
<li class="is-active orbit-slide">
<img class="orbit-image" src="assets/img/orbit/01.jpg" alt="Space">
<figcaption class="orbit-caption">Space, the final frontier.</figcaption>
</li>
<li class="orbit-slide">
<img class="orbit-image" src="assets/img/orbit/02.jpg" alt="Space">
<figcaption class="orbit-caption">Lets Rocket!</figcaption>
</li>
<li class="orbit-slide">
<img class="orbit-image" src="assets/img/orbit/03.jpg" alt="Space">
<figcaption class="orbit-caption">Encapsulating</figcaption>
</li>
<li class="orbit-slide">
<img class="orbit-image" src="assets/img/orbit/04.jpg" alt="Space">
<figcaption class="orbit-caption">Outta This World</figcaption>
</li>
</ul>
<nav class="orbit-bullets">
<button class="is-active" data-slide="0"><span class="show-for-sr">First slide details.</span><span class="show-for-sr">Current Slide</span></button>
<button data-slide="1"><span class="show-for-sr">Second slide details.</span></button>
<button data-slide="2"><span class="show-for-sr">Third slide details.</span></button>
<button data-slide="3"><span class="show-for-sr">Fourth slide details.</span></button>
</nav>
</div>
将 vue components
与 foundation js components
一起使用时出现问题,这就是为什么它们没有按照说明显示 here
所以我在我的脚本标签中添加了这个指令:
Vue.directive('f-orbit', {
bind: function (el) {
new Foundation.Orbit($(el))
},
unbind: function (el) {
$(el).foundation.destroy()
}
})
并且在我的模板中我添加了 v-f-orbit
而不是默认的 data-orbit
:
<div class="contemporary orbit" role="region" aria-label="Contemporary Pictures" v-f-orbit>
我希望这对遇到困难的人有所帮助。
Phillis 的上述回答完全正确。只是想我会抛出另一个例子,Foundation 6.4 dropdown-menu
和 Vue.js 2
.
创建名为 dropdown
的自定义指令并将 v-dropdown
添加到父元素,它应该可以正常工作。
<ul class="dropdown menu" v-dropdown>
<li>
<a href="#">Navigate Site <i class="fas fa-chevron-down"></i></a>
<ul class="menu vertical">
<li><a href="/auto"><i class="far fa-car"></i> Auto</a></li>
<li><a href="/residential"><i class="far fa-home"></i> Residential</a></li>
<li><a href="/commercial"><i class="far fa-building"></i> Commercial</a></li>
<li><a href="/safety-security"><i class="far fa-building"></i> Safety & Security</a></li>
<li><a href="/specialty-solutions"><i class="far fa-gem"></i> Specialty Solutions</a></li>
<li><a href="/dealers"><i class="fal fa-id-badge"></i></i> Dealers</a></li>
<li><a href="/madicou"><i class="far fa-building"></i> Madico U</a></li>
<li><a href="/about"><i class="far fa-building"></i> Company</a></li>
</ul>
</li>
</ul>
Vue.directive('dropdown', {
bind: function (el) {
new Foundation.DropdownMenu($(el));
}
});
我意识到在失败的组件内部使用 Zurb Foundation classes in .vue single file components. At first I could not get a Reveal Modal to work inside the .vue component
but it was working when I use the same code in a blade
or html
file. Then I noticed a pattern because when I tried to use the Foundation's Orbit 时存在问题,起初我认为这是一个错误,但后来我在 blade
文件中使用了相同的代码并且有效。其他基础 类,例如 row
、grid
和 buttons
工作正常。
有没有人遇到过同样的问题?我该如何解决?
模态代码如下:
<a data-open="video" class="button warning" href="">WATCH VIDEO</a>
<div id="video" class="reveal" data-reveal>
<div class="lead">
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="flex-video">
<iframe width="1280" height="720" :src="url" frameborder="0" allowfullscreen></iframe>
</div>
</div>
对于轨道,我使用了基础文档中的基本示例进行测试。
<div class="orbit" role="region" aria-label="Favorite Space Pictures" data-orbit>
<ul class="orbit-container">
<button class="orbit-previous"><span class="show-for-sr">Previous Slide</span>◀︎</button>
<button class="orbit-next"><span class="show-for-sr">Next Slide</span>▶︎</button>
<li class="is-active orbit-slide">
<img class="orbit-image" src="assets/img/orbit/01.jpg" alt="Space">
<figcaption class="orbit-caption">Space, the final frontier.</figcaption>
</li>
<li class="orbit-slide">
<img class="orbit-image" src="assets/img/orbit/02.jpg" alt="Space">
<figcaption class="orbit-caption">Lets Rocket!</figcaption>
</li>
<li class="orbit-slide">
<img class="orbit-image" src="assets/img/orbit/03.jpg" alt="Space">
<figcaption class="orbit-caption">Encapsulating</figcaption>
</li>
<li class="orbit-slide">
<img class="orbit-image" src="assets/img/orbit/04.jpg" alt="Space">
<figcaption class="orbit-caption">Outta This World</figcaption>
</li>
</ul>
<nav class="orbit-bullets">
<button class="is-active" data-slide="0"><span class="show-for-sr">First slide details.</span><span class="show-for-sr">Current Slide</span></button>
<button data-slide="1"><span class="show-for-sr">Second slide details.</span></button>
<button data-slide="2"><span class="show-for-sr">Third slide details.</span></button>
<button data-slide="3"><span class="show-for-sr">Fourth slide details.</span></button>
</nav>
</div>
将 vue components
与 foundation js components
一起使用时出现问题,这就是为什么它们没有按照说明显示 here
所以我在我的脚本标签中添加了这个指令:
Vue.directive('f-orbit', {
bind: function (el) {
new Foundation.Orbit($(el))
},
unbind: function (el) {
$(el).foundation.destroy()
}
})
并且在我的模板中我添加了 v-f-orbit
而不是默认的 data-orbit
:
<div class="contemporary orbit" role="region" aria-label="Contemporary Pictures" v-f-orbit>
我希望这对遇到困难的人有所帮助。
Phillis 的上述回答完全正确。只是想我会抛出另一个例子,Foundation 6.4 dropdown-menu
和 Vue.js 2
.
创建名为 dropdown
的自定义指令并将 v-dropdown
添加到父元素,它应该可以正常工作。
<ul class="dropdown menu" v-dropdown>
<li>
<a href="#">Navigate Site <i class="fas fa-chevron-down"></i></a>
<ul class="menu vertical">
<li><a href="/auto"><i class="far fa-car"></i> Auto</a></li>
<li><a href="/residential"><i class="far fa-home"></i> Residential</a></li>
<li><a href="/commercial"><i class="far fa-building"></i> Commercial</a></li>
<li><a href="/safety-security"><i class="far fa-building"></i> Safety & Security</a></li>
<li><a href="/specialty-solutions"><i class="far fa-gem"></i> Specialty Solutions</a></li>
<li><a href="/dealers"><i class="fal fa-id-badge"></i></i> Dealers</a></li>
<li><a href="/madicou"><i class="far fa-building"></i> Madico U</a></li>
<li><a href="/about"><i class="far fa-building"></i> Company</a></li>
</ul>
</li>
</ul>
Vue.directive('dropdown', {
bind: function (el) {
new Foundation.DropdownMenu($(el));
}
});