对不起新手问题.但是如何从selectbox中获取所选元素的索引并运行一个函数.我下面的代码不会触发switchView()函数.
<select id="selectbox" @change="switchView(index)">
<option [v-for="(item, index) in items" v-bind:value="item.title"]>
{{ item.title }}
</option>
</select>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
编辑:
移动@change="switchView(index)"从<option>到<select>,由于@Phil
我需要索引,因为我有几个计算项目.我需要根据用户对项目的选择来更改视图.
我正在尝试创建WebRTC视频聊天。现在,我被放在创建媒体轨道按钮上(将视频静音以启用或禁用视频发送,将音频静音以使其与音频相同)。这是我的代码。
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.peerjs.com/0.3/peer.min.js"></script>
<script>
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
var myStream;
var peer = new Peer({key: 'PeerJS key'});
var setOthersStream = function(stream){
$('#others-video').prop('src', URL.createObjectURL(stream));
};
var setMyStream = function(stream){
myStream = stream;
$('#video').prop('src', URL.createObjectURL(stream));
};
peer.on('open', function(id){
$('#peer-id').text(id);
});
peer.on('call', function(call){
call.answer(myStream);
call.on('stream', setOthersStream);
});
$(function(){
navigator.getUserMedia({audio: true, video: true}, setMyStream, function(){});
$('#call').on('click', function(){
var call = peer.call($('#others-peer-id').val(), myStream);
call.on('stream', setOthersStream);
});
});
peer.on('error', function(e){
console.log(e.message);
});
Run Code Online (Sandbox Code Playgroud)
谁能指导我?
我想切换元素,并且需要一个类名。如何获取stimulus.js 中嵌套元素的类名并更改它?FI,我需要切换最初隐藏的“ul”元素。
div data-controller="my_controller"
a data-action="click->my_controller#toggle_my_elements"
| Click
ul.is-hidden id="my-id" data-target="my_controller.mytext"
li
| Text to be toggled.
Run Code Online (Sandbox Code Playgroud)
在刺激控制器中我有:
import { Controller } from 'stimulus'
export default class extends Controller {
static targets = ["mytext"]
toggle_my_elements(){
console.log("debuggin") //Ok
const class_name = this.mytextTarget.className
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试调用 js 函数className,但似乎 js 函数不再像以前那样工作。我只是不知道如何得到它。