[英]How to keep active listGroup after reload page?
I'm creating a gallery with the #listGroup bootstrap component. 我正在使用#listGroup引导程序组件创建画廊。 I want when one of the albums in the click change the active #listGroup even the page is reload or refresh. 我想要当单击的相册之一更改活动的#listGroup时,即使页面已重新加载或刷新。 How do I fix this? 我该如何解决?
HTML/PHP HTML / PHP
<div class="container">
<div class="row">
<h2 class="col-xs-12">Gallery</h2>
</div><!-- /row -->
<div class="row">
<div class="col-xs-12 col-sm-3">
<div class="list-group" id='listGroup'>
<?php
include 'dismin/pages/koneksi.php';
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * 12;
$sql = "SELECT * FROM tbl_album where status='process' ORDER BY albumid DESC LIMIT $start_from, 12";
$rs_result = mysql_query ($sql);
####### Fetch Results From Table ########
$no=0;
while ($row = mysql_fetch_assoc($rs_result))
{
$aid=$row['albumid'];
$aname=$row['name'];
?>
<a href="gallery?id=<?php echo $aid; ?>" class="list-group-item" v-bind:class="{ 'active' : isSelected(<?php echo $no; ?>) }" v-on:click="selected = <?php echo $no++; ?>"><?php echo $aname; ?></a>
<?php } ?>
</div>
</div><!-- /col -->
<div class="col-xs-12 col-sm-9">
<div class="row">
<?php
include "dismin/pages/koneksi.php";
$aid = $_GET['id'];
$sql = "SELECT * FROM tbl_gallery where aid=$aid and status='process'";
$num_rows = mysql_num_rows(mysql_query($sql));
####### Fetch Results From Table ########
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$gimage=$row['gimages'];
?>
<div class="col-xs-12 col-sm-4">
<a href="#" class="thumbnail">
<img src="dismin/pages/galeri/aksi/gupload/<?php echo $gimage; ?>">
</a>
</div><!-- /col -->
<?php } ?>
</div><!-- /row -->
</div><!-- /col -->
</div><!-- /row -->
</div><!-- /container -->
JAVASCRIPT JAVASCRIPT
new Vue({
el: '#listGroup',
data: {
selected: 0
},
methods: {
isSelected: function (i) {
return i === this.selected
}
}
})
As was mentioned in a comment, the state needs to be persisted. 正如评论中提到的那样, 国家必须保持下去。
data: {
selected: <?php echo $aid; ?>;
}
If the JS code is in another file then add a JS variable from the PHP code. 如果JS代码在另一个文件中,则从PHP代码中添加一个JS变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.